31 #elif __linux__ || __APPLE__
33 #include <linux/types.h>
35 #include <sys/prctl.h>
38 #include <sys/ioctl.h>
42 #include <sys/types.h>
47 #include <semaphore.h>
52 #include <sys/syscall.h>
53 #include <sys/resource.h>
82 static const int g_map_preset_to_gopsize[2][18] = {{8, 0, 1, -1, 1, 2, 4, -1, 4, 8, 1, 4, -1, -1, -1, -1, 16},
83 {8, 0, -1, -1, -1, 2, 4, -1, -1, 8, 1, -1, -1, -1, -1, -1, -1}};
84 #define MAGIC_P2P_VALUE "p2p"
100 0x00, 0x00, 0x00, 0x01,
118 0x00, 0x00, 0x00, 0x01,
134 0x00, 0x00, 0x00, 0x01,
150 0x00, 0x00, 0x00, 0x01,
168 #define NI_XCODER_FAILURES_MAX 25
169 #define DP_IPC_PASSTHRU 0xFFFFFFFF
172 #ifdef XCODER_SELF_KILL_ERR
173 #undef XCODER_SELF_KILL_ERR
180 for (i = 0; i < bytes; i += 2)
182 uint8_t val = buf[i];
190 uint32_t i, words = (bytes + 1) / 2;
192 for (i = 0; i < words; i += 2)
194 uint16_t val = buf[i];
202 uint32_t i, words = (bytes + 3) / 4;
203 for (i = 0; i < words; i += 2)
205 uint32_t val = buf[i];
213 uint64_t i, words = (bytes + 7) / 8;
214 for (i = 0; i < words; i += 2)
216 uint64_t val = buf[i];
222 static void memcpyToPelByBits (uint8_t *dst_u8, uint8_t *src,
int width,
int height,
int dst_stride,
int src_stride,
int srcValidBitsDepth)
225 uint8_t bitsDepth = srcValidBitsDepth;
226 uint32_t mask = (1<<bitsDepth)-1;
227 uint16_t *dst = (uint16_t *)dst_u8;
232 for (j = 0; j < height; j ++)
234 for (i = 0; i< width; i ++)
235 dst_u8[i] = src[i] & 0xff;
238 dst_u8 += dst_stride;
244 for (j = 0; j < height; j ++)
246 uint8_t *src_line = src;
247 uint32_t cache = 0, cache_bits = 0;
248 for (i = 0; i< width; i ++)
250 while(cache_bits < bitsDepth)
252 cache |= ((*src_line++) << cache_bits);
256 if (cache_bits >= bitsDepth)
258 dst[i] = cache & mask;
260 cache_bits -= bitsDepth;
285 static void trace_recon_tile2raster_y(FILE *fRecon, uint8_t *mem,
int width,
int height,
286 int leftOffset,
int topOffset,
287 int src_stride,
int pixDepth, uint8_t *luma_mem_temp)
290 int write_data_len = 0;
291 int bytesPerPix = (pixDepth == 8 ? 1 : 2);
292 uint8_t *tmp_mem = (uint8_t *)malloc(bytesPerPix*src_stride);
293 int num_tiles = (leftOffset + width + 3) / 4 - leftOffset/4;
296 mem += topOffset/4*4*src_stride + leftOffset/4*16*pixDepth/8;
297 for(i = topOffset/4*4; i < topOffset + height; i += 4) {
298 memcpyToPelByBits(tmp_mem, mem, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
299 if(i >= topOffset && i < topOffset + height){
301 memcpy(luma_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
302 write_data_len += width * bytesPerPix;
304 memcpyToPelByBits(tmp_mem, mem+4*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
305 if(i+1 >= topOffset && i+1 < topOffset + height)
308 memcpy(luma_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
309 write_data_len += width * bytesPerPix;
311 memcpyToPelByBits(tmp_mem, mem+8*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
312 if(i+2 >= topOffset && i+2 < topOffset + height)
315 memcpy(luma_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
316 write_data_len += width * bytesPerPix;
318 memcpyToPelByBits(tmp_mem, mem+12*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
319 if(i+3 >= topOffset && i+3 < topOffset + height)
322 memcpy(luma_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
323 write_data_len += width * bytesPerPix;
330 static void trace_recon_tile2raster_uv(FILE *fRecon, uint8_t *mem_uv,
int width,
int height,
331 int leftOffset,
int topOffset,
332 int src_stride,
int pixDepth, uint8_t *ch_mem_temp)
335 int bytesPerPix = (pixDepth == 8 ? 1 : 2);
336 uint8_t *tmp_mem = (uint8_t *)malloc(bytesPerPix*src_stride*2);
337 int num_tiles = 2*((leftOffset + width + 3) / 4 - leftOffset/4);
342 int write_data_len = 0;
343 memset(tmp_mem, 0x00, bytesPerPix * src_stride * 2);
344 for(uv = 0; uv <= 1; uv ++) {
345 mem = mem_uv + topOffset/4*8*src_stride + leftOffset/4*32*pixDepth/8;
346 for(i = topOffset/4*4; i < topOffset + height; i += 4) {
347 if(i >= topOffset && i < topOffset + height) {
348 memcpyToPelByBits(tmp_mem, mem, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
349 for(j = uv, k = 0; j < 4 * num_tiles; j += 2, k++) {
351 tmp_mem[k] = tmp_mem[j];
353 ((uint16_t*)tmp_mem)[k] = ((uint16_t*)tmp_mem)[j];
356 memcpy(ch_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
357 write_data_len += width * bytesPerPix;
359 if(i+1 >= topOffset && i+1 < topOffset + height) {
360 memcpyToPelByBits(tmp_mem, mem+4*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
361 for(j = uv, k = 0; j < 4 * num_tiles; j += 2, k++) {
363 tmp_mem[k] = tmp_mem[j];
365 ((uint16_t*)tmp_mem)[k] = ((uint16_t*)tmp_mem)[j];
368 memcpy(ch_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
369 write_data_len += width * bytesPerPix;
371 if(i+2 >= topOffset && i+2 < topOffset + height) {
372 memcpyToPelByBits(tmp_mem, mem+8*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
373 for(j = uv, k = 0; j < 4 * num_tiles; j += 2, k++) {
375 tmp_mem[k] = tmp_mem[j];
377 ((uint16_t*)tmp_mem)[k] = ((uint16_t*)tmp_mem)[j];
380 memcpy(ch_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
381 write_data_len += width * bytesPerPix;
383 memcpyToPelByBits(tmp_mem, mem+12*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
384 if(i+3 >= topOffset && i+3 < topOffset + height) {
385 for(j = uv, k = 0; j < 4 * num_tiles; j += 2, k++) {
387 tmp_mem[k] = tmp_mem[j];
389 ((uint16_t*)tmp_mem)[k] = ((uint16_t*)tmp_mem)[j];
392 memcpy(ch_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
393 write_data_len += width * bytesPerPix;
401 static double calc_noise(uint8_t *p1, uint8_t *p2,
int size)
408 for (i = 0; i < size; i++)
410 diff = p1[i] - p2[i];
455 FILE *fout_raster = NULL;
470 uint8_t *luma_mem_temp = NULL;
471 uint8_t *ch_mem_temp = NULL;
499 SwapSW16((uint16_t *)luma_mem, lum_sz);
500 SwapSW32((uint32_t *)luma_mem, lum_sz);
501 SwapSW64((uint64_t *)luma_mem, lum_sz);
502 trace_recon_tile2raster_y (fout_raster, luma_mem, width, height,
513 SwapSW16((uint16_t *)ch_mem, chr_sz);
514 SwapSW32((uint32_t *)ch_mem, chr_sz);
515 SwapSW64((uint64_t *)ch_mem, chr_sz);
516 trace_recon_tile2raster_uv(fout_raster, ch_mem, width / 2, height / 2,
533 double noise_y = 0.0, noise_u = 0.0, noise_v = 0.0, noise_yuv = 0.0;
534 double power_y = 0.0, power_u = 0.0, power_v = 0.0, power_yuv = 0.0;
535 double psnr_y = 0.0, psnr_u = 0.0, psnr_v = 0.0, psnr_yuv = 0.0;
544 uint8_t *p_y_src_buf = NULL;
545 uint8_t *p_u_src_buf = NULL;
546 uint8_t *p_v_src_buf = NULL;
547 for (
int i = 0; i < 120; i++)
562 if (p_y_src_buf != NULL)
566 noise_y = calc_noise(p_y_src_buf, luma_mem_temp, width * height);
570 noise_u = calc_noise(p_u_src_buf, ch_mem_temp, (width / 2) * (height / 2));
571 noise_v = calc_noise(p_v_src_buf, ch_mem_temp + (width / 2) * (height / 2), (width / 2) * (height / 2));
573 noise_yuv = noise_y + noise_u + noise_v;
577 noise_y = noise_y < 1 ? 1 : noise_y;
578 noise_u = noise_u < 1 ? 1 : noise_u;
579 noise_v = noise_v < 1 ? 1 : noise_v;
580 noise_yuv = noise_yuv < 1 ? 1 : noise_yuv;
583 power_y = 1.0 * max * max * width * height;
584 power_u = power_y / 4.0;
585 power_v = power_y / 4.0;
586 power_yuv = power_y * 3.0 / 2.0;
590 psnr_y = 10 * log10(power_y / noise_y);
594 psnr_u = 10 * log10(power_u / noise_u);
595 psnr_v = 10 * log10(power_v / noise_v);
597 psnr_yuv = 10 * log10(power_yuv / noise_yuv);
602 ni_log2(p_ctx,
NI_LOG_DEBUG,
"pkt_num %d psnr_y %.4f psnr_u %.4f psnr_v %.4f psnr_yuv %.4f width %d height %d reconLumaSize 0x%x reconChromaSize 0x%x\n",
610 luma_mem_temp = NULL;
634 uint16_t ui16ErrorCount = 0;
635 uint32_t ui32LastErrorStatus = 0;
657 else if(opt ==
OPT_2){
667 ui16ErrorCount > 0 && !retval &&
673 else if(opt ==
OPT_3)
682 "Persistent failures detected, %s() line-%d: session_no 0x%x "
683 "sess_err_count %u inst_err_no %u\n",
684 func, line, *(inst_id), ui16ErrorCount,
685 ui32LastErrorStatus);
686 #ifdef XCODER_SELF_KILL_ERR
689 kill(getpid(), SIGTERM);
701 #define CHECK_ERR_RC(ctx, rc, info, opcode, type, hw_id, inst_id, opt) \
703 (rc) = check_err_rc(ctx, rc, info, opcode, type, hw_id, inst_id, opt, __func__, __LINE__); \
704 if((rc) && ((opt) != OPT_3)) LRETURN; \
707 #define CHECK_VPU_RECOVERY(ret) \
709 if (NI_RETCODE_NVME_SC_VPU_RECOVERY == (ret)) \
711 ni_log(NI_LOG_ERROR, "Error, vpu reset.\n"); \
712 (ret) = NI_RETCODE_ERROR_VPU_RECOVERY; \
722 "decoder" :
"encoder";
726 uint64_t abs_time_ns;
733 ts.tv_sec = abs_time_ns / 1000000000LL;
734 ts.tv_nsec = abs_time_ns % 1000000000LL;
744 if (ret == ETIMEDOUT)
756 "decoder" :
"encoder";
786 #elif __linux__ || __APPLE__
788 char dir_name[128] = {0};
789 char file_name[512] = {0};
792 struct dirent *stream_folder;
793 int curr_stream_idx = 0;
794 int earliest_stream_idx = 0;
795 int max_exist_idx = 0;
796 time_t earliest_time = 0;
797 struct stat file_stat;
801 if (!p_device_context)
808 flock(p_device_context->lock, LOCK_EX);
811 if (0 != access(dir_name, F_OK))
813 if (0 != mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO))
823 if (NULL == (dir = opendir(dir_name)))
832 while ((stream_folder = readdir(dir)))
834 if (!strncmp(stream_folder->d_name,
"stream", strlen(
"stream")))
837 atoi(&(stream_folder->d_name[strlen(
"stream")]));
838 if (curr_stream_idx > 0)
840 if (curr_stream_idx > max_exist_idx)
842 max_exist_idx = curr_stream_idx;
857 curr_stream_idx = max_exist_idx + 1;
861 while ((stream_folder = readdir(dir)))
865 if (!strncmp(stream_folder->d_name,
"stream", strlen(
"stream")))
867 snprintf(file_name,
sizeof(file_name),
"%s/%s/pkt-0001.bin",
868 dir_name, stream_folder->d_name);
871 atoi(&(stream_folder->d_name[strlen(
"stream")]));
873 if (curr_stream_idx > 0 && 0 == access(file_name, F_OK))
876 if (stat(file_name, &file_stat))
883 if (0 == earliest_stream_idx ||
884 file_stat.st_mtime < earliest_time)
886 earliest_stream_idx = curr_stream_idx;
887 earliest_time = file_stat.st_mtime;
894 curr_stream_idx = earliest_stream_idx;
898 snprintf(file_name,
sizeof(file_name),
"%s/stream%03d/pkt-0001.bin",
899 dir_name, curr_stream_idx);
900 if (utime(file_name, NULL))
909 "%s/stream%03d", dir_name, curr_stream_idx);
928 flock(p_device_context->lock, LOCK_UN);
931 snprintf(file_name,
sizeof(file_name),
"%s/process_session_id.txt",
934 fp = fopen(file_name,
"wb");
937 char number[64] = {
'\0'};
939 snprintf(number,
sizeof(number),
"proc id: %ld\nsession id: %u\n",
941 fwrite(number, strlen(number), 1, fp);
963 char *dom, *bus, *dev, *fnc;
972 p_ctx->
netint_fd = open(
"/dev/netint", O_RDWR);
980 if (stat(p_dev, &bstat) < 0)
986 if ((bstat.st_mode & S_IFMT) != S_IFBLK)
993 ret = snprintf(syspath,
sizeof(syspath) - 1,
994 "/sys/block/%s/device/address",
998 fp = fopen(syspath,
"r");
1000 ret = snprintf(syspath,
sizeof(syspath) - 1,
1001 "udevadm info -q path -n %s | perl -nle'print $& "
1002 "while m{(?<=/)[0-9a-f]{4}:[0-9a-f]{2}:[0-9a-f]{2}\\.[0-9a-f]}g' | tail -n 1",
1004 syspath[ret] =
'\0';
1006 fp = popen(syspath,
"r");
1015 if (fgets(line, 256, fp) == NULL)
1033 p_ctx->
domain = strtoul(line, &dom, 16);
1041 p_ctx->
bus = strtoul(dom + 1, &bus, 16);
1049 p_ctx->
dev = strtoul(bus + 1, &dev, 16);
1058 p_ctx->
fn = strtoul(dev + 1, &fnc, 16);
1067 p_ctx->
bus, p_ctx->
dev, p_ctx->
fn);
1074 #if __linux__ || __APPLE__
1076 #ifndef DISABLE_BACKTRACE_PRINT
1077 void ni_print_backtrace() {
1078 void* callstack[128];
1079 int frames = backtrace(callstack, 128);
1080 char** strs = backtrace_symbols(callstack, frames);
1083 for (
int i = 0; i < frames; ++i) {
1104 void* p_buffer = NULL;
1105 uint32_t ui32LBA = 0;
1106 char fmt_fw_api_ver1[5], fmt_fw_api_ver2[5];
1149 "ERROR %d: %s() alloc decoder all zero buffer failed\n",
1190 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n", __func__,
1199 uint64_t keep_alive_timeout =
1202 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
1204 keep_alive_timeout);
1215 "ERROR %s(): nvme write keep_alive_timeout command "
1216 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
1232 __func__, fmt_fw_api_ver1, fmt_fw_api_ver2);
1243 "ERROR %s(): nvme write sw_version command "
1244 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
1267 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n", __func__,
1275 "%s(): p_ctx->device_handle=0x%" PRIx64
", p_ctx->hw_id=%d, "
1276 "p_ctx->session_id=%d\n",
1339 ni_log2(p_ctx,
NI_LOG_INFO,
"Warn %s(): forceLowDelay is not available for fw < 6r3\n",
1350 "%s(): p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, "
1351 "p_ctx->session_id=%d\n",
1357 decoder_dump_dir_open(p_ctx);
1360 #ifdef XCODER_DUMP_DATA
1361 char dir_name[256] = {0};
1363 snprintf(dir_name,
sizeof(dir_name),
"%ld-%u-dec-fme", (
long)getpid(),
1365 DIR *dir = opendir(dir_name);
1368 mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
1394 uint32_t ui32LBA = 0;
1405 if (NI_INVALID_DEVICE_HANDLE == device_handle)
1418 "session_id=%d\n", __func__, (int64_t)device_handle, session_id);
1424 "SUCCESS %s(): device_handle=%" PRIx64
" , "
1425 "session_id=%d\n", __func__, (int64_t)device_handle, session_id);
1536 void* p_buffer = NULL;
1537 uint32_t ui32LBA = 0;
1566 "Decoder_complete_info:session_id 0x%x, total frames input:%u "
1567 "buffered: %u completed: %u output: %u dropped: %u error: %u\n",
1613 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
1614 "p_ctx->session_id=%d, close_mode=1\n",
1683 low_delay_signal(p_ctx);
1700 uint32_t sent_size = 0;
1701 uint32_t packet_size = 0;
1702 int current_pkt_size;
1707 int query_retry = 0;
1708 uint32_t ui32LBA = 0;
1712 if ((!p_ctx) || (!p_packet))
1729 low_delay_wait(p_ctx);
1731 #ifdef MEASURE_LATENCY
1736 abs_time_ns, p_packet->
dts);
1742 current_pkt_size = packet_size;
1745 int max_retry = 200;
1823 "Warning: dec write query fail rc %d or available buf size %u < "
1824 "pkt size %u , retry: %d max_retry_fail_count %d\n",
1827 if (query_retry > max_retry)
1845 "size %u >= pkt size %u !\n",
1888 "%s() had data to send: packet_size=%u, "
1889 "p_packet->sent_size=%d, p_packet->data_len=%u, "
1890 "p_packet->start_of_stream=%u, p_packet->end_of_stream=%u, "
1891 "p_packet->video_width=%u, p_packet->video_height=%u\n",
1896 uint8_t *p_data = (uint8_t *)p_packet->
p_data;
1907 p_data, packet_size, ui32LBA);
1926 char dump_file[512] = {0};
1929 snprintf(dump_file,
sizeof(dump_file),
"%s/pkt-%04ld.bin",
1931 FILE *f = fopen(dump_file,
"wb");
1934 fwrite(p_packet->
p_data, sent_size, 1, f);
1973 "%s: pkt_index %d pkt_offsets_index %" PRIu64
1974 " pts_offsets %" PRId64
"\n",
1982 "%s(): more than NI_MAX_DEC_REJECT frames are rejected by the "
1983 "decoder. Increase NI_MAX_DEC_REJECT is required or default "
1984 "gen pts values will be used !\n",
2003 "%s: (first packet) pkt_index %d i %u "
2004 "pkt_offsets_index_min %" PRIu64
" pkt_offsets_index %" PRIu64
2005 " pts_offsets %" PRId64
"\n",
2017 "%s: pkt_index %d i %u pkt_offsets_index_min "
2018 "%" PRIu64
" pkt_offsets_index %" PRIu64
" pts_offsets %" PRId64
2031 "%s: (wrap) pkt_index %d i %u "
2032 "pkt_offsets_index_min %" PRIu64
" pkt_offsets_index %" PRIu64
2033 " pts_offsets %" PRId64
"\n",
2056 "Error %s: failed to allocate custom SEI buffer for pkt.\n",
2072 "ERROR %s(): ni_timestamp_register() for dts returned %d\n",
2082 "%s(): exit: packets: %" PRIu64
" offset %" PRIx64
""
2083 " sent_size = %u, status=%d\n",
2084 __func__, p_ctx->
pkt_num, (uint64_t)p_packet->
pos, sent_size,
2090 "ERROR %s(): exit: returnErr: %d, p_ctx->status: %d\n", __func__,
2096 static int64_t guess_correct_pts(
ni_session_context_t* p_ctx, int64_t reordered_pts, int64_t dts)
2104 "%s: pts_correction_last_dts %" PRId64
" "
2105 "pts_correction_num_faulty_dts %d\n",
2120 "%s: pts_correction_last_pts %" PRId64
" "
2121 "pts_correction_num_faulty_pts %d\n",
2134 pts = reordered_pts;
2146 pts = reordered_pts;
2154 static int rotated_array_binary_search(uint64_t *lefts, uint64_t *rights,
2155 int32_t size, uint64_t target)
2161 int mid = lo + (hi - lo) / 2;
2162 if (lefts[mid] <= target && target < rights[mid])
2167 if (rights[mid] == 0)
2174 if (rights[lo] <= rights[mid])
2176 if (lefts[lo] <= target && target < lefts[mid])
2187 if (rights[mid] <= target && target < rights[hi])
2213 uint64_t frame_offset = 0;
2214 uint8_t *p_data_buffer = NULL;
2220 uint32_t total_bytes_to_read = 0;
2221 uint32_t read_size_bytes = 0;
2226 int query_retry = 0;
2227 uint32_t ui32LBA = 0;
2228 unsigned int bytes_read_so_far = 0;
2230 int low_delay_notify = 0;
2231 uint32_t frames_dropped = 0;
2232 uint8_t get_first_metadata = 0;
2233 uint8_t sequence_change = 0;
2237 if ((!p_ctx) || (!p_frame))
2255 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
2260 p_frame->
data_len[2] + metadata_hdr_size;
2311 ni_log2(p_ctx,
NI_LOG_TRACE,
"Warning: dec read query fail rc %d retry %d max_retry_fail_count %d\n",
2314 if (query_retry >= 1000)
2317 low_delay_notify = 1;
2334 total_bytes_to_read = metadata_hdr_size;
2335 sequence_change = 1;
2358 "WARNING: Dec eos reached but also exceeded max dec read query "
2359 "retries. is_flushed=%u try=%d.\n",
2364 "Dec eos reached. is_flushed=%u try=%d.\n",
2368 low_delay_notify = 1;
2374 " retrying ..\n", query_retry);
2388 query_retry < 1000 / 2)
2395 low_delay_signal(p_ctx);
2410 low_delay_signal(p_ctx);
2413 "Warning: ceased using low delay decoding mode after "
2414 "excessively long decoder read query.\n");
2417 low_delay_signal(p_ctx);
2427 if(query_retry <= 2000)
2436 "Warning: decoder pkt_num %u frame_num %u "
2437 "timeout, increaing pkt_delay_cnt to %u\n",
2461 "At least %d packets should be sent before reading the "
2478 "%ux%u frame-rate %u is_flushed %u\n",
2512 #ifdef XCODER_SELF_KILL_ERR
2517 kill(getpid(), SIGTERM);
2534 p_frame->
data_len[2] + metadata_hdr_size;
2535 p_data_buffer = (uint8_t*) p_frame->
p_buffer;
2547 "%u cb len %u hdr %d\n",
2550 p_frame->
data_len[2], metadata_hdr_size);
2556 "ERROR %s() avaliable size(%u)"
2557 "less than needed (%u)\n",
2569 void *p_metadata_buffer = NULL;
2575 "ERROR %d: %s() Cannot allocate metadata buffer.\n",
2580 p_data_buffer = (uint8_t *)p_metadata_buffer;
2581 get_first_metadata = 1;
2582 sequence_change = 0;
2596 p_data_buffer, read_size_bytes, ui32LBA);
2605 }
else if (get_first_metadata) {
2613 get_first_metadata = 0;
2627 low_delay_notify = 1;
2640 total_bytes_to_read = total_bytes_to_read + sei_size;
2642 "include sei %u sei_size %d\n",
2643 retval, total_bytes_to_read, sei_size);
2646 bytes_read_so_far = total_bytes_to_read ;
2650 rx_size =
ni_create_frame(p_frame, bytes_read_so_far, &frame_offset,
false);
2665 "is cancelled due to has_b_frames, frame_num %u\n",
2700 if (p_frame->
pts >= p_frame->
dts &&
2701 p_frame->
pts - p_frame->
dts < 1000)
2749 uint64_t num_fw_pkts =
2752 "%s: num_fw_pkts %" PRIu64
" frame_offset %" PRIu64
"\n",
2753 __func__, num_fw_pkts,
2757 bool bFound = (num_fw_pkts >= cumul);
2758 while (cumul < num_fw_pkts)
2764 "NI_MAX_DEC_REJECT!\n");
2772 "pkt_offsets_index[idx] %" PRIu64
"\n",
2782 "%s: (first frame) idx %d last_dts %" PRId64
""
2783 "dts %" PRId64
" last_pts %" PRId64
" pts %" PRId64
"\n",
2790 "%s(): session %u recovering and "
2801 "%s: (zero default) dts %" PRId64
" pts "
2803 __func__, p_frame->
dts, p_frame->
pts);
2810 "%s: (not bitstream) dts %" PRId64
" pts "
2812 __func__, p_frame->
dts, p_frame->
pts);
2817 int64_t pts_delta = p_frame->
dts - p_ctx->
last_dts;
2822 "%s: (!is_first_frame idx) last_dts %" PRId64
""
2823 "dts %" PRId64
" pts_delta %" PRId64
" last_pts "
2824 "%" PRId64
" pts %" PRId64
"\n",
2825 __func__, p_ctx->
last_dts, p_frame->
dts, pts_delta,
2849 "%s: (found pts) dts %" PRId64
" pts "
2850 "%" PRId64
" frame_offset %" PRIu64
" i %d "
2851 "pkt_offsets_index_min %" PRIu64
" pkt_offsets_index "
2852 "%" PRIu64
" pkt_pos %" PRIu64
" \n",
2853 __func__, p_frame->
dts, p_frame->
pts, frame_offset, i,
2874 "ERROR: Frame pts %" PRId64
" not found for offset "
2875 "%" PRIu64
"\n", p_frame->
pts, frame_offset);
2877 "%s: (not found use default) dts %" PRId64
" pts %" PRId64
2879 __func__, p_frame->
dts, p_frame->
pts);
2886 p_frame->
pts = guess_correct_pts(p_ctx, p_frame->
pts, p_frame->
dts);
2894 __func__, p_frame->
pts);
2897 #ifdef MEASURE_LATENCY
2904 #ifdef XCODER_DUMP_DATA
2905 char dump_file[256];
2906 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-dec-fme/fme-%04ld.yuv",
2908 FILE *f = fopen(dump_file,
"wb");
2919 "%s(): p_frame->start_of_stream=%u, "
2920 "p_frame->end_of_stream=%u, p_frame->video_width=%u, "
2921 "p_frame->video_height=%u\n",
2930 "Decoder pts queue size = %u dts queue size = %u\n\n",
2937 #ifdef MEASURE_LATENCY
2953 if (get_first_metadata && p_data_buffer)
2955 if (sequence_change && p_ctx->
frame_num)
2970 low_delay_signal(p_ctx);
2976 if (low_delay_notify)
2978 low_delay_signal(p_ctx);
2998 device_type, g_device_type_str[device_type]);
3021 switch (device_type)
3043 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s blk_dev %s blk_xcoder %s dev_xcoder %s current_load:%u model_load:%u fw_load:%u "
3044 "total_contexts:%u fw_video_mem_usage:%u "
3045 "fw_video_shared_mem_usage:%u fw_share_mem_usage:%u "
3046 "fw_p2p_mem_usage:%u active_hwuploaders:%u\n", __func__,
3062 "Overall load %u, model load %u, instance count %u\n",
3089 device_type, g_device_type_str[device_type]);
3120 void *p_buffer = NULL;
3122 uint32_t ui32LBA = 0;
3123 uint32_t max_cu_size;
3124 uint32_t block_size;
3125 int32_t width, height;
3126 int m_threshold = 0;
3127 char fmt_fw_api_ver1[5], fmt_fw_api_ver2[5];
3145 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() RGBA / BGRA / ARGB / AGBR resolution invalid, return\n",
3164 width = (width / 8) * 8;
3165 height = (height / 8) * 8;
3169 ((width + max_cu_size - 1) & (~(max_cu_size - 1))) *
3170 ((height + max_cu_size - 1) & (~(max_cu_size - 1))) /
3172 p_ctx->
roi_len = ((block_size + 63) & (~63));
3250 "ERROR %s(): p_ctx->device_handle=%" PRIx64
", "
3251 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
3262 uint64_t keep_alive_timeout =
3265 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
3267 keep_alive_timeout);
3278 "ERROR %s(): nvme write keep_alive_timeout command "
3279 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
3295 __func__, fmt_fw_api_ver1, fmt_fw_api_ver2);
3306 "ERROR %s(): nvme write sw_version command "
3307 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
3347 ni_log2(p_ctx,
NI_LOG_ERROR,
"The bit depth or resoultion is not supported on ai enhance mode\n");
3361 "ERROR %s(): p_ctx->device_handle=%" PRIx64
", "
3362 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
3397 if (m_threshold > 4 * 1024 * 1024 *
sizeof(
long))
3400 "DEFAULT_MMAP_THRESHOLD_MAX, use default value (%d)\n",
3401 m_threshold, 4 * 1024 * 1024 *
sizeof(
long));
3402 m_threshold = 4 * 1024 * 1024 *
sizeof(long);
3407 #if defined(__linux__) && !defined(_ANDROID)
3411 if (mallopt(M_MMAP_THRESHOLD, m_threshold) == 0)
3424 if (mallopt(M_TRIM_THRESHOLD, 3 * m_threshold) == 0)
3433 "Warning: this platform does not support staticMmapThreshold\n");
3440 m_threshold = (int) (m_threshold * 1.25);
3441 void *temp_buf = malloc((
size_t) m_threshold);
3442 ni_log2(p_ctx,
NI_LOG_TRACE,
"trigger a pre-mature increase in mmap&trim threshold: 0x%p = malloc(%d)\n",
3443 temp_buf, m_threshold);
3471 for (uint8_t ui8Index = 0; ui8Index < 20; ui8Index++)
3494 "p_ctx->sender_handle=%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%u\n",
3503 "p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%u\n",
3509 if ((sender_vf_ns_id.
ns_id != curr_vf_ns_id.
ns_id) ||
3510 (sender_vf_ns_id.
vf_id != curr_vf_ns_id.
vf_id))
3527 "p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
3538 "ERROR: ni_ai_query_network_ready returned %d\n", retval);
3571 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() line-%d return %d\n", __func__, __LINE__, retval);
3587 "%s(): p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, "
3588 "p_ctx->session_id=%d\n",
3592 #ifdef XCODER_DUMP_DATA
3593 char dir_name[256] = {0};
3594 snprintf(dir_name,
sizeof(dir_name),
"%ld-%u-enc-pkt", (
long)getpid(),
3596 DIR *dir = opendir(dir_name);
3599 mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
3607 snprintf(dir_name,
sizeof(dir_name),
"%ld-%u-enc-fme", (
long)getpid(),
3609 dir = opendir(dir_name);
3612 mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
3683 void* p_buffer = NULL;
3684 uint32_t ui32LBA = 0;
3709 "Encoder_complete_info:session_id 0x%x, total frames input:%u "
3710 "buffered: %u completed: %u output: %u dropped: %u error: %u\n",
3750 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
3751 "p_ctx->session_id=%d, close_mode=1\n",
3819 for (i = 0; i < 120 ; i++)
3833 low_delay_signal(p_ctx);
3844 int32_t width_stride[4] = {0};
3845 int32_t height_stride[4] = {0};
3862 width_stride, height_stride);
3865 for (
int i = 0; i < 120; i++)
3886 for (
int j = 0; j < source_height; j++)
3889 ni_frame->
p_data[0] + j * width_stride[0],
3892 for (
int j = 0; j < (source_height + 1) / 2; j++)
3895 ni_frame->
p_data[1] + j * width_stride[1],
3898 for (
int j = 0; j < (source_height + 1) / 2; j++)
3901 ni_frame->
p_data[2] + j * width_stride[2],
3917 for (
int j = 0; j < source_height; j++)
3920 ni_frame->
p_data[0] + j * width_stride[0],
3923 for (
int j = 0; j < (source_height + 1) / 2; j++)
3926 ni_frame->
p_data[1] + j * width_stride[1],
3929 for (
int j = 0; j < (source_height + 1) / 2; j++)
3932 ni_frame->
p_data[2] + j * width_stride[2],
3955 bool ishwframe =
false;
3957 uint32_t send_count = 0;
3959 uint32_t sent_size = 0;
3960 uint32_t frame_size_bytes = 0;
3965 if (!p_ctx || !p_frame)
3978 if (!((input_frame_idx > 0 &&
3984 __func__, input_frame_idx);
4003 low_delay_wait(p_ctx);
4005 #ifdef MEASURE_LATENCY
4032 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: passed video_height and video_width are not valid!, return\n");
4044 "%s: data_len[0] %u data_len[1] %u "
4045 "data_len[2] %u extra_data_len %u frame_size_bytes %u\n",
4079 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() line-%d retrun %d\n", __func__, __LINE__, retval);
4086 "Enc write query retry %d. rc=%d. Available buf size %u < "
4087 "frame size %u\n", retval, send_count,
4091 int retval_backup = retval;
4104 "Enc write query buf info exceeded max retries: "
4105 "%d, rc=%d. Available buf size %u < frame size %u\n",
4119 "Info enc write query success, available buf "
4120 "size %u >= frame size %u !\n",
4129 if (separate_metadata)
4135 p_frame->
p_data[2 + ishwframe] +
4150 "use_cur_src_as_long_term_pic %d use_long_term_ref %d\n",
4165 "%s(): ctx->force_frame_type"
4166 " %d frame->force_key_frame %d force frame_num %" PRIu64
""
4208 "%s(): %d.%u p_ctx->frame_num=%" PRIu64
", "
4209 "p_frame->start_of_stream=%u, p_frame->end_of_stream=%u, "
4210 "p_frame->video_width=%u, p_frame->video_height=%u, pts=0x%08x 0x%08x, "
4211 "dts=0x%08x 0x%08x, sei_len=%u, roi size=%u avg_qp=%u reconf_len=%u "
4212 "force_pic_qp=%u use_cur_src_as_long_term_pic %u use_long_term_ref "
4213 "%u start_len [%u,%u,%u] inconsecutive_transfer %u\n",
4217 (uint32_t)(p_frame->
pts & 0xFFFFFFFF),
4218 (uint32_t)((p_frame->
dts >> 32) & 0xFFFFFFFF),
4264 "ni_timestamp_register() for dts returned: %d\n",
4268 if (separate_metadata)
4270 uint32_t ui32LBA_metadata =
4273 "%s: p_metadata_buffer = %p, metadata_buffer_size "
4274 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4303 "%s: p_start_buffer = %p, p_frame->start_buffer_size "
4304 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4332 "%s: p_data = %p, p_frame->buffer_size "
4333 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4365 "%s: p_data = %p, p_frame->buffer_size "
4366 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4370 sent_size = frame_size_bytes;
4371 if (separate_metadata)
4404 int ret =
hwdl_frame(p_ctx, &hwdl_session_data, p_frame,
4425 "%s(): session=0x%x ui16FrameIdx=%u\n",
4433 size = frame_size_bytes;
4436 #ifdef XCODER_DUMP_DATA
4437 char dump_file[256];
4438 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-enc-fme/fme-%04ld.yuv",
4441 FILE *f = fopen(dump_file,
"wb");
4464 uint32_t actual_read_size = 0;
4465 uint32_t to_read_size = 0;
4467 static long long encq_count = 0LL;
4469 int query_retry = 0;
4471 uint32_t ui32LBA = 0;
4476 int low_delay_notify = 0;
4479 if (!p_ctx || !p_packet || !p_packet->
p_data)
4499 ni_log2(p_ctx,
NI_LOG_DEBUG,
"frame_num=%" PRIu64
", pkt_num=%" PRIu64
", av1_pkt_num=%" PRIu64
"\n",
4512 low_delay_notify = 1;
4544 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: initial_frame_delay %d max_frame_delay %d ui8AdditionalFramesDelay %u current_frame_delay %d\n",
4558 "Info enc read query rc %d, available buf size %u, "
4559 "frame_num=%" PRIu64
", pkt_num=%" PRIu64
"\n",
4596 "%" PRIu64
" >= %" PRIu64
" pkt_num, keep querying p_ctx->status %d\n",
4604 low_delay_notify = 1;
4621 ni_log2(p_ctx,
NI_LOG_TRACE,
"%s: low delay mode 2, keep reading send frame %d receive pkt %d gop %d current_frame_delay %d\n",
4622 __FUNCTION__, p_ctx->
frame_num, pkt_num,
4644 actual_read_size = to_read_size;
4657 "ERROR %s(): packet buffer size %u allocation "
4659 __func__, actual_read_size);
4666 p_packet->
p_data, actual_read_size, ui32LBA);
4688 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s MetaDataSize %d FrameType %d AvgFrameQp %d ssim %d %d %d\n",
4706 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: current gop_size %u last_gop_size %d initial_frame_delay %d max_frame_delay %d current_frame_delay %d\n",
4718 ni_log2(p_ctx,
NI_LOG_DEBUG,
"max_mv x[0] %d x[1] %d y[0] %d y[1] %d min_mv x[0] %d x[1] %d y[0] %d y[1] %d frame_size %u inter_total_count %u intra_total_count %u\n",
4727 if (p_meta->
ssimY != 0)
4732 #ifdef NI_LOG_SSIM_AT_INFO
4737 "%s: pkt #%" PRId64
" pts %" PRId64
" ssim "
4738 "Y %.4f U %.4f V %.4f\n", __FUNCTION__, p_ctx->
pkt_num,
4739 p_packet->
pts, (
float)p_meta->
ssimY/10000,
4740 (
float)p_meta->
ssimU/10000, (
float)p_meta->
ssimV/10000);
4784 low_delay_notify = 1;
4789 #ifdef MEASURE_LATENCY
4796 #ifdef XCODER_DUMP_DATA
4797 char dump_file[256];
4798 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-enc-pkt/pkt-%04ld.bin",
4801 FILE *f = fopen(dump_file,
"wb");
4811 "%s(): %d.%u p_packet->start_of_stream=%u, "
4812 "p_packet->end_of_stream=%u, p_packet->video_width=%u, "
4813 "p_packet->video_height=%u, p_packet->dts=0x%08x 0x%08x, "
4814 "p_packet->pts=0x%08x 0x%08x, type=%u, avg_frame_qp=%u, show_frame=%d\n",
4817 (uint32_t)((p_packet->
dts >> 32) & 0xFFFFFFFF),
4818 (uint32_t)(p_packet->
dts & 0xFFFFFFFF),
4819 (uint32_t)((p_packet->
pts >> 32) & 0xFFFFFFFF),
4820 (uint32_t)(p_packet->
pts & 0xFFFFFFFF), p_packet->
frame_type,
4826 if (encq_count % 500 == 0)
4829 "Encoder pts queue size = %u dts queue size = %u\n\n",
4835 #ifdef MEASURE_LATENCY
4855 if (low_delay_notify)
4857 low_delay_signal(p_ctx);
4881 p_ctx->
last_gop_size = g_map_preset_to_gopsize[lookAheadEnable][gop_preset_index + 1];
4893 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR %s(): config encoder sequence change command failed\n",
4918 void* p_buffer = NULL;
4919 uint32_t ui32LBA = 0;
4920 char fmt_fw_api_ver1[5], fmt_fw_api_ver2[5];
4935 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Cannot use stack filter on device with FW API version < 6.4\n");
4945 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Cannot use rotate filter on device with FW API version < 6.7\n");
4955 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Cannot use in-place overlay filter on device with FW API version < 6.L\n");
5022 "ERROR %s(): p_ctx->device_handle=%" PRIx64
5023 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
5031 "%s(): p_ctx->device_handle=%" PRIx64
5032 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
5037 uint64_t keep_alive_timeout =
5040 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
5042 keep_alive_timeout);
5053 "ERROR %s(): nvme write keep_alive_timeout command "
5054 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
5070 __func__, fmt_fw_api_ver1, fmt_fw_api_ver2);
5081 "ERROR %s(): nvme write sw_version command "
5082 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
5101 retval = p2p_fill_pcie_address(p_ctx);
5128 void * p_buffer = NULL;
5129 uint32_t ui32LBA = 0;
5163 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
5164 "p_ctx->session_id=%d, close_mode=1\n",
5216 void *p_scaler_config = NULL;
5220 uint32_t ui32LBA = 0;
5224 if (!p_ctx || !p_params)
5250 memset(p_scaler_config, 0, buffer_size);
5262 p_scaler_config, buffer_size, ui32LBA);
5263 if ((int32_t)retval < 0)
5266 "ERROR: ni_nvme_send_write_cmd failed: blk_io_handle: %" PRIx64
5267 ", hw_id, %d, xcoder_inst_id: %d\n",
5274 "ERROR: %s failed: blk_io_handle: %" PRIx64
","
5275 "hw_id, %d, xcoder_inst_id: %d\n",
5320 int rectangle_width,
5321 int rectangle_height,
5330 uint32_t ui32LBA = 0;
5331 uint32_t query_retry = 0;
5336 dataLen = dataLen & 0xFFFFF000;
5353 if (rgba_color == 0)
5360 "WARNING: Allocate framepool size 0 for session 0x%x\n", p_ctx->
session_id);
5366 "ERROR: %s() try to free session 0x%x framepool while it's not allocated\n",
5377 "ERROR: %s() try to free session 0x%x framepool of type %u while "
5378 "passing type %u\n",
5393 "ERROR: allocate framepool multiple times for session 0x%x "
5394 "not supported in FW API version < 6r3\n",
5401 "Expand frame pool of scaler 0x%x with %u more frames\n",
5407 "ERROR: try to expand session 0x%x framepool with type %u "
5408 "while pool type is %u\n",
5423 memset(p_data, 0x00, dataLen);
5425 p_data->picture_width = width;
5426 p_data->picture_height = height;
5427 p_data->picture_format = format;
5428 p_data->options = options;
5429 p_data->rectangle_width = rectangle_width;
5430 p_data->rectangle_height = rectangle_height;
5431 p_data->rectangle_x = rectangle_x;
5432 p_data->rectangle_y = rectangle_y;
5433 p_data->rgba_color = rgba_color;
5434 p_data->frame_index = frame_index;
5441 ni_log2(p_ctx,
NI_LOG_ERROR,
"Resolution %d x %d not supported for %d format!\n", width, height, format);
5446 "Session=0x%x: Dev alloc frame: FrameIndex=%d; W=%d; H=%d; C=%d; RW=%d; RH=%d; RX=%d; RY=%d\n",
5448 p_data->picture_width, p_data->picture_height,
5449 p_data->picture_format, p_data->rectangle_width,
5450 p_data->rectangle_height, p_data->rectangle_x, p_data->rectangle_y);
5460 p_data, dataLen, ui32LBA);
5487 "ERROR: ni_nvme_send_admin_cmd failed: "
5488 "blk_io_handle: %" PRIx64
", hw_id, %u, xcoder_inst_id: %d\n",
5517 uint32_t ui32LBA = 0;
5522 dataLen = dataLen & 0xFFFFF000;
5524 if (!p_ctx || !p_cfg)
5543 memset(p_data, 0x00, dataLen);
5548 p_data->options = p_cfg->
options;
5567 p_data->orientation = 3;
5570 p_data->orientation = 1;
5582 ni_log2(p_ctx,
NI_LOG_ERROR,
"Resolution %d x %d not supported for %d format!\n", p_data->picture_width, p_data->picture_height, p_data->picture_format);
5588 "Session=0x%x: Dev config frame: FrameIndex=%u; W=%d; H=%d; C=%d; RW=%d; RH=%d; RX=%d; RY=%d; O=%d\n",
5590 p_data->picture_width, p_data->picture_height,
5591 p_data->picture_format, p_data->rectangle_width,
5592 p_data->rectangle_height, p_data->rectangle_x,
5593 p_data->rectangle_y, p_data->orientation);
5599 p_data, dataLen, ui32LBA);
5605 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
5606 ", hw_id, %u, xcoder_inst_id: %d\n",
5610 "ERROR ni_scaler_config(): nvme command failed!\n");
5641 uint32_t ui32LBA = 0;
5647 dataLen = dataLen & 0xFFFFF000;
5649 if (!p_ctx || (!p_cfg_in && numInCfgs))
5668 memset(p_data, 0x00, dataLen);
5670 p_data_orig = p_data;
5672 for (i = 0; i < numInCfgs; i++)
5689 "Session=0x%x: Dev in config frame %d: FrameIndex=%u; Session=0x%x; W=%d; H=%d; C=%d; RW=%d; RH=%d; RX=%d; RY=%d\n",
5691 p_data->frame_index, p_data->session_id,
5692 p_data->picture_width, p_data->picture_height,
5693 p_data->picture_format, p_data->rectangle_width,
5694 p_data->rectangle_height, p_data->rectangle_x, p_data->rectangle_y);
5714 "Session=0x%x: Dev out config frame: FrameIndex=%u; W=%d; H=%d; C=%d; RW=%d; RH=%d; RX=%d; RY=%d\n",
5716 p_data->picture_width, p_data->picture_height,
5717 p_data->picture_format, p_data->rectangle_width,
5718 p_data->rectangle_height, p_data->rectangle_x,
5719 p_data->rectangle_y);
5723 ni_log2(p_ctx,
NI_LOG_ERROR,
"Resolution %d x %d not supported for %d format!\n", p_data->picture_width, p_data->picture_height, p_data->picture_format);
5732 p_data_orig, dataLen, ui32LBA);
5738 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
5739 ", hw_id, %u, xcoder_inst_id: %d\n",
5743 "ERROR ni_scaler_config(): nvme command failed!\n");
5765 void* p_buffer = NULL;
5767 uint32_t ui32LBA = 0;
5772 if ((!p_ctx) || (!p_gen_status))
5783 __func__, device_type);
5798 memset(p_buffer, 0, dataLen);
5811 p_gen_status->fw_model_load, p_gen_status->cmd_queue_count,
5812 p_gen_status->process_load_percent);
5833 void* p_buffer = NULL;
5835 uint32_t ui32LBA = 0;
5836 uint32_t dataLen = 0;
5837 uint32_t copyLen = 0;
5858 if ((!p_ctx) || (!p_detail_status))
5869 __func__, device_type);
5882 memset(p_buffer, 0, dataLen);
5892 memcpy(p_detail_status, p_buffer, copyLen);
5915 void* p_buffer = NULL;
5917 uint32_t ui32LBA = 0;
5922 if ((!p_ctx) || (!p_stream_info))
5934 __func__, device_type);
5956 memset(p_buffer, 0, dataLen);
5968 p_stream_info->picture_width = ni_htons(p_stream_info->picture_width);
5969 p_stream_info->picture_height = ni_htons(p_stream_info->picture_height);
5970 p_stream_info->frame_rate = ni_htons(p_stream_info->frame_rate);
5971 p_stream_info->is_flushed = ni_htons(p_stream_info->is_flushed);
5972 p_stream_info->transfer_frame_stride = ni_htons(p_stream_info->transfer_frame_stride);
5974 p_stream_info->pix_format);
6002 void* p_buffer = NULL;
6003 uint64_t session_timestamp;
6004 uint32_t ui32LBA = 0;
6013 if ((!p_ctx) || (!p_session_stats))
6024 __func__, device_type);
6046 memset(p_buffer, 0, dataLen);
6066 p_session_stats->ui16SessionId = ni_htons(p_session_stats->ui16SessionId);
6067 p_session_stats->ui16ErrorCount = ni_htons(p_session_stats->ui16ErrorCount);
6068 p_session_stats->ui32LastTransactionId =
6069 ni_htonl(p_session_stats->ui32LastTransactionId);
6070 p_session_stats->ui32LastTransactionCompletionStatus =
6071 ni_htonl(p_session_stats->ui32LastTransactionCompletionStatus);
6072 p_session_stats->ui32LastErrorTransactionId = ni_htonl(p_session_stats->ui32LastErrorTransactionId);
6073 p_session_stats->ui32LastErrorStatus = ni_htonl(p_session_stats->ui32LastErrorStatus);
6074 p_session_stats->ui32Session_timestamp_high = ni_htonl(p_session_stats->ui32Session_timestamp_high);
6075 p_session_stats->ui32Session_timestamp_low = ni_htonl(p_session_stats->ui32Session_timestamp_low);
6077 session_timestamp = p_session_stats->ui32Session_timestamp_high;
6078 session_timestamp <<= 32;
6079 session_timestamp |= p_session_stats->ui32Session_timestamp_low;
6087 p_session_stats->ui32LastErrorStatus =
6090 "query timestamp:%" PRIu64
"\n", p_ctx->
session_id,
6099 ni_log2(p_ctx,
NI_LOG_ERROR,
"%s(): session id %u ts %lu hw_id %d device_type %u codec_format %u frame_num %lu pkt_num %lu "
6100 "ready_to_close %u session_run_state %d active_video_width %u active_video_height %u\n",
6114 #if __linux__ || __APPLE__
6116 #ifndef DISABLE_BACKTRACE_PRINT
6117 ni_print_backtrace();
6122 p_session_stats->ui32LastTransactionCompletionStatus =
6126 }
else if (p_ctx->
session_id != p_session_stats->ui16SessionId)
6131 "%s(): device 0x%" PRIx64
" last command Failed due to wrong "
6132 "session ID. Expected 0x%x, got 0x%x keep alive last access "
6133 "time %" PRIu64
", current %" PRIu64
"\n", __func__,
6136 if (dt > 1000000000)
6139 "%s():long delay between last command dt = %" PRId64
" ns, "
6140 "process was possibly blocked.\n", __func__, dt);
6149 __func__, p_session_stats->ui16ErrorCount,
6150 p_session_stats->ui32LastTransactionCompletionStatus,
6151 p_session_stats->ui32LastErrorStatus);
6174 void* p_buffer = NULL;
6176 uint32_t ui32LBA = 0;
6181 if (!p_ctx || !p_stream_complete)
6193 __func__, device_type);
6215 memset(p_buffer, 0, dataLen);
6227 p_stream_complete->is_flushed = ni_htons(p_stream_complete->is_flushed);
6237 static const char* ni_get_device_type_str(
int type)
6241 return "Invalid device type";
6243 return g_device_type_str[type];
6251 memcpy((
void *)p_session_statistic, p_buffer,
6255 p_session_statistic->ui32RdBufAvailSize =
6256 ni_htonl(p_session_statistic->ui32RdBufAvailSize);
6257 p_session_statistic->ui32WrBufAvailSize =
6258 ni_htonl(p_session_statistic->ui32WrBufAvailSize);
6260 p_session_statistic->ui32FramesInput =
6261 ni_htonl(p_session_statistic->ui32FramesInput);
6262 p_session_statistic->ui32FramesBuffered =
6263 ni_htonl(p_session_statistic->ui32FramesBuffered);
6264 p_session_statistic->ui32FramesCompleted =
6265 ni_htonl(p_session_statistic->ui32FramesCompleted);
6266 p_session_statistic->ui32FramesOutput =
6267 ni_htonl(p_session_statistic->ui32FramesOutput);
6268 p_session_statistic->ui32FramesDropped =
6269 ni_htonl(p_session_statistic->ui32FramesDropped);
6270 p_session_statistic->ui32InstErrors =
6271 ni_htonl(p_session_statistic->ui32InstErrors);
6273 p_session_statistic->ui16SessionId =
6274 ni_htons(p_session_statistic->ui16SessionId);
6275 p_session_statistic->ui16ErrorCount =
6276 ni_htons(p_session_statistic->ui16ErrorCount);
6277 p_session_statistic->ui32LastTransactionId =
6278 ni_htonl(p_session_statistic->ui32LastTransactionId);
6279 p_session_statistic->ui32LastTransactionCompletionStatus =
6280 ni_htonl(p_session_statistic->ui32LastTransactionCompletionStatus);
6281 p_session_statistic->ui32LastErrorTransactionId =
6282 ni_htonl(p_session_statistic->ui32LastErrorTransactionId);
6283 p_session_statistic->ui32LastErrorStatus =
6284 ni_htonl(p_session_statistic->ui32LastErrorStatus);
6285 p_session_statistic->ui32Session_timestamp_high =
6286 ni_htonl(p_session_statistic->ui32Session_timestamp_high);
6287 p_session_statistic->ui32Session_timestamp_low =
6288 ni_htonl(p_session_statistic->ui32Session_timestamp_low);
6292 if (p_ctx->
session_id != p_session_statistic->ui16SessionId)
6297 "%s(): %s device 0x%" PRIx64
" last command Failed due to wrong "
6298 "session ID. Expected 0x%x, got 0x%x w_r <%u %u> keep alive "
6299 "last access time %" PRIu64
", current %" PRIu64
"\n", __func__,
6302 p_session_statistic->ui16SessionId,
6303 p_session_statistic->ui32WrBufAvailSize,
6306 if (dt > 1000000000)
6309 "%s():long delay between last command dt = %" PRId64
" ns, "
6310 "process was possibly blocked.\n", __func__, dt);
6312 p_session_statistic->ui32LastErrorStatus =
6322 __func__, p_session_statistic->ui16ErrorCount,
6323 p_session_statistic->ui32LastTransactionCompletionStatus,
6324 p_session_statistic->ui32LastErrorStatus);
6344 void *p_buffer = NULL;
6346 uint32_t ui32LBA = 0;
6352 if (!p_ctx || !p_session_statistic)
6355 "ERROR: %s() passed parameters are null!, return\n", __func__);
6363 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() not supported on device with FW api version < 6.5\n", __func__);
6372 __func__, device_type);
6394 memset(p_buffer, 0, dataLen);
6403 p_buffer, dataLen, ui32LBA) < 0)
6414 ni_parse_session_statistic_info(p_ctx, p_session_statistic, p_buffer);
6419 __func__, ni_get_device_type_str(p_ctx->
device_type));
6448 void* p_buffer = NULL;
6450 uint32_t ui32LBA = 0;
6458 if (!p_ctx || !p_inst_buf_info)
6472 __func__, device_type);
6539 memset(p_buffer, 0, dataLen);
6550 p_inst_buf_info->buf_avail_size = ni_htonl(p_inst_buf_info->buf_avail_size);
6576 uint8_t enable, uint8_t hw_action,
6580 uint32_t ui32LBA = 0;
6581 void * p_buffer = NULL;
6582 uint32_t buffer_size = 0;
6611 memset(p_buffer, 0, buffer_size);
6670 uint32_t ui32LBA = 0;
6686 __func__, device_type);
6724 uint32_t ui32LBA = 0;
6740 __func__, device_type);
6779 uint32_t ui32LBA = 0;
6794 __func__, device_type);
6841 uint32_t ui32LBA = 0;
6842 void * p_buffer = NULL;
6843 uint32_t buffer_size = 0;
6859 __func__, device_type);
6880 memset(p_buffer, 0, buffer_size);
6881 memcpy(p_buffer, &len,
sizeof(len));
6911 uint32_t ui32LBA = 0;
6912 void * p_buffer = NULL;
6913 uint32_t buffer_size = 0;
6927 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Seq Change not supported for device type %d, return\n", device_type);
6948 memset(p_buffer, 0, buffer_size);
6976 void* p_encoder_config = NULL;
6980 uint32_t ui32LBA = 0;
7007 memset(p_encoder_config, 0, buffer_size);
7068 p_encoder_config, buffer_size, ui32LBA);
7105 uint32_t ui32LBA = 0;
7109 if (!p_ctx || !p_params)
7143 buffer_size, ui32LBA) < 0)
7174 if (!p_frame || !p_frame_offset)
7181 *p_frame_offset = 0;
7185 unsigned int video_data_size = p_frame->
data_len[0] + p_frame->
data_len[1] +
7192 if (rx_size == metadata_size)
7194 video_data_size = 0;
7197 if (rx_size > video_data_size)
7204 rx_size -= metadata_size;
7216 "%s: [metadata] cropRight=%u, cropLeft=%u, "
7217 "cropBottom=%u, cropTop=%u, frame_offset=%" PRIu64
", pic=%ux%u, "
7218 "pict_type=%d, crop=%ux%u, sei header: 0x%0x number %u size %u\n",
7242 #if 1 // QUADRA_SEI_FMT
7243 ni_log(
NI_LOG_DEBUG,
"ui32SeiHeader 0x%x ui16SeiNumber %d ui16SeiSize %d SEI 0x%02x%02x\n",
7245 *((uint8_t*)p_meta + metadata_size),
7246 *((uint8_t*)p_meta + metadata_size+1));
7249 uint16_t ui16SeiProcessed = 0;
7251 uint32_t ui32Offset = 0;
7260 if (pEntryHeader->
status)
7262 ui32Size = pEntryHeader->
size;
7270 ui16SeiProcessed, pEntryHeader->
status,
7271 pEntryHeader->
size, pEntryHeader->
type, ui32Size,
7273 *((uint8_t *)p_meta + metadata_size + ui32Offset),
7274 *((uint8_t *)p_meta + metadata_size + ui32Offset + 1));
7281 switch(pEntryHeader->
type)
7286 uint8_t *ptr = (uint8_t*)p_meta + metadata_size + ui32Offset;
7293 video_data_size + metadata_size + ui32Offset;
7320 "%s: close caption size %u ,"
7321 "offset %u = video size %u meta size %d off "
7324 video_data_size, metadata_size, ui32Offset);
7329 "%s: unsupported T35; type %u size %u status %u "
7331 __func__, pEntryHeader->
type, pEntryHeader->
size,
7332 pEntryHeader->
status, ui32Offset);
7338 "Error %s: T35 (missing payload); type %u size %u "
7339 "status %u offset %u\n",
7340 __func__, pEntryHeader->
type, pEntryHeader->
size,
7341 pEntryHeader->
status, ui32Offset);
7358 "Error %s: User Data Unreg dropped (missing payload); "
7359 "type %u size %u status %u offset %u\n",
7360 __func__, pEntryHeader->
type, pEntryHeader->
size,
7361 pEntryHeader->
status, ui32Offset);
7370 video_data_size + metadata_size + ui32Offset;
7375 *)((uint8_t *)p_meta + metadata_size + ui32Offset);
7397 "Error %s: mastering display info dropped (missing "
7398 "payload); type %u size %u status %u offset %u\n",
7399 __func__, pEntryHeader->
type, pEntryHeader->
size,
7400 pEntryHeader->
status, ui32Offset);
7409 video_data_size + metadata_size + ui32Offset;
7415 (uint8_t*)p_meta + metadata_size + ui32Offset);
7424 "Error %s: content light level info dropped (missing "
7425 "payload); type %u size %u status %u offset %u\n",
7426 __func__, pEntryHeader->
type, pEntryHeader->
size,
7427 pEntryHeader->
status, ui32Offset);
7436 video_data_size + metadata_size + ui32Offset;
7443 "Error %s: SEI message dropped (unsupported - check "
7444 "decoder SEI bitmap settings);"
7445 " type %u size %u status %u offset %u payload bytes %u\n",
7446 __func__, pEntryHeader->
type, pEntryHeader->
size,
7447 pEntryHeader->
status, ui32Offset, ui32Size);
7450 ui32Offset += ui32Size;
7451 pEntryHeader = (
ni_sei_header_t *)((uint8_t*)p_meta + metadata_size + ui32Offset);
7453 }
while (ui32Offset <= p_meta->sei_size && ui16SeiProcessed < p_meta->sei_number);
7459 "Error %s: number of SEI messages reported %u != processed %u\n",
7460 __func__, p_meta->
sei_number, ui16SeiProcessed);
7464 #else // QUADRA_SEI_FMT
7469 ni_sei_user_data_entry_t *pEntry;
7470 uint32_t ui32CCOffset = 0, ui32CCSize = 0;
7474 pEntry = (ni_sei_user_data_entry_t *)((uint8_t*)p_meta + metadata_size);
7477 &ui32CCOffset, &ui32CCSize))
7481 video_data_size + metadata_size + ui32CCOffset;
7494 &ui32CCOffset, &ui32CCSize))
7498 ptr = (uint8_t*)pEntry + ui32CCOffset;
7501 ui32CCSize = (ptr[8] & 0x1F) * 3;
7507 + ui32CCOffset + 10;
7512 "%s: close caption size %u ,"
7513 "offset %u = video size %u meta size %u off "
7516 video_data_size, metadata_size, ui32CCOffset);
7526 &ui32CCOffset, &ui32CCSize))
7530 video_data_size + metadata_size + ui32CCOffset;
7534 ni_dec_mastering_display_colour_volume_t* pColourVolume =
7535 (ni_dec_mastering_display_colour_volume_t*)((uint8_t*)pEntry + ui32CCOffset);
7538 pColourVolume->display_primaries_x[0],
7539 pColourVolume->display_primaries_y[0]);
7541 pColourVolume->display_primaries_x[1],
7542 pColourVolume->display_primaries_y[1]);
7544 pColourVolume->display_primaries_x[2],
7545 pColourVolume->display_primaries_y[2]);
7548 pColourVolume->white_point_x,
7549 pColourVolume->white_point_y);
7551 pColourVolume->max_display_mastering_luminance, pColourVolume->min_display_mastering_luminance);
7555 &ui32CCOffset, &ui32CCSize))
7559 video_data_size + metadata_size + ui32CCOffset;
7563 ni_content_light_level_info_t* pLightLevel =
7564 (ni_content_light_level_info_t*)((uint8_t*)pEntry + ui32CCOffset);
7566 pLightLevel->max_content_light_level, pLightLevel->max_pic_average_light_level);
7571 &ui32CCOffset, &ui32CCSize) ||
7574 &ui32CCOffset, &ui32CCSize))
7578 video_data_size + metadata_size + ui32CCOffset;
7585 #endif // QUADRA_SEI_FMT
7621 int i, total_types = 0, total_modules = 0;
7629 if (!p_cap || !p_data)
7642 "ERROR: Previously in context device got an invalid vendor ID 0x%X SSVID 0x%X. Netint "
7643 "ID 0x%X. Retrying\n",
7647 (
int)
sizeof(p_id_data->
ai8Sn), p_id_data->
ai8Sn);
7649 (
int)
sizeof(p_id_data->
ai8Mn), p_id_data->
ai8Mn);
7651 (
int)
sizeof(p_id_data->
ai8Fr), p_id_data->
ai8Fr);
7655 ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
7666 "ERROR: %s(): Retry got an invalid vendor ID too 0x%X SSVID "
7671 (
int)
sizeof(p_id_data->
ai8Sn), p_id_data->
ai8Sn);
7673 (
int)
sizeof(p_id_data->
ai8Mn), p_id_data->
ai8Mn);
7675 (
int)
sizeof(p_id_data->
ai8Fr), p_id_data->
ai8Fr);
7683 "Retry got valid a vendor ID 0x%X SSVID 0x%X. Netint ID 0x%X\n",
7722 "Error: mismatch; xcoder_num_elements: %d (calculated: %d) "
7723 "xcoder_num_devices: %d (calculated: %d)\n",
7780 "ERROR: Previously in context device is not a xcoder device "
7800 if (total_modules >= 1)
7815 if (total_modules >= 2)
7830 if (total_modules >= 3)
7845 if (total_modules >= 4)
7913 static uint32_t presetGopSize[] = {
7924 static uint32_t presetGopKeyFrameFactor[] = {
7944 int pos_byte = (pos/8);
7945 int pos_in_byte = pos%8;
7946 int remaining_bytes_in_current_byte = 8 - pos_in_byte;
7948 if (pos_in_byte == 0)
7950 vui[pos_byte] = (uint8_t)(value >> 24);
7951 vui[pos_byte+1] = (uint8_t)(value >> 16);
7952 vui[pos_byte+2] = (uint8_t)(value >> 8);
7953 vui[pos_byte+3] = (uint8_t)(value);
7957 vui[pos_byte] = vui[pos_byte] + (uint8_t)(value >> (32-remaining_bytes_in_current_byte));
7958 vui[pos_byte+1] = (uint8_t)(value >> (32-remaining_bytes_in_current_byte-8));
7959 vui[pos_byte+2] = (uint8_t)(value >> (32-remaining_bytes_in_current_byte-16));
7960 vui[pos_byte+3] = (uint8_t)(value >> (32-remaining_bytes_in_current_byte-24));
7961 vui[pos_byte+4] = vui[pos_byte+4] + ((uint8_t)(value << remaining_bytes_in_current_byte));
7976 uint32_t max_pkt_size)
7980 if ((!p_ctx) || (!p_cfg) || (!p_src))
7989 bool shift_params =
false;
8017 ni_log2(p_ctx,
NI_LOG_INFO,
"%s height %d width %d fps_number %d fps_denominator %d\n",
8027 shift_params =
true;
8028 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Output 2 used before output 1, Shifting output2 settings to output1 and disabling output 2\n");
8033 if (!shift_params || i == 0)
8039 j = (i == 1) ? 2 : 1;
8045 (uint16_t)((p_dec->
crop_whxy[j][0]) & 0xFFFE);
8047 (uint16_t)((p_dec->
crop_whxy[j][1]) & 0xFFFE);
8049 (uint16_t)((p_dec->
crop_whxy[j][2]) & 0xFFFE);
8051 (uint16_t)((p_dec->
crop_whxy[j][3]) & 0xFFFE);
8103 (uint16_t)((p_dec->
scale_wh[j][0]+1) & 0xFFFE);
8105 (uint16_t)((p_dec->
scale_wh[j][1]+1) & 0xFFFE);
8120 ni_log2(p_ctx,
NI_LOG_ERROR,
"WARN: set ui8EnablePpuScaleLimit to 0 when ui8EnablePpuScaleAdapt is disabled.\n");
8129 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): maxExtraHwFrameCnt is not support for FW < 6rB\n", __func__);
8136 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): (enableAdvancedEc == 2) is not support for FW < 6rO\n", __func__);
8194 if ((!p_ctx) || (!p_cfg) || (!p_src))
8236 ni_log2(p_ctx,
NI_LOG_DEBUG,
"### %s: Slow sequence happened retain last_bitrate %d. assigned bitrate %d\n",
8254 ni_log2(p_ctx,
NI_LOG_DEBUG,
"force enable_mb_level_rc & enable_cu_level_rate_control to 0 because rate control is disabled\n");
8304 ni_log2(p_ctx,
NI_LOG_DEBUG,
"### %s: Slow sequence happened retain last_framerate num %d den %d. assigned num %d den %d\n",
8322 uint32_t numUnitsInTick = 1000;
8387 "ERROR: %s() unknown value for p_t408->decoding_refresh_type: %d\n",
8411 ni_log2(p_ctx,
NI_LOG_DEBUG,
"force intraRefreshMode to 1 because quadra only supports intra refresh by rows\n");
8421 int mbRows = (p_cfg->
i32picHeight + mbHeight - 1) / mbHeight;
8456 "for profile 3 (extended) or 1 (baseline)\n");
8465 "force EnableRdoQuant 0 to accommodate HW limiation\n");
8585 if (p_enc->
crf != -1)
8733 "Turning off strongIntraSmoothing because hvsQPEnable=1 "
8734 "for better subjective VQ\n");
8746 "Turning off strongIntraSmoothing because hvsQPEnable=1 for "
8747 "better subjective VQ\n");
8819 int gopSize = g_map_preset_to_gopsize[lookAheadEnable][p_t408->
gop_preset_index + 1];
8825 if (lookAheadEnable)
8827 int firstGopEnd = gopSize + 1 + mulitcoreDelay;
8828 int lookaheadGopEnd = mulitcoreDelay ?
8831 int initialDelayNum = (firstGopEnd > lookaheadGopEnd) ? firstGopEnd : lookaheadGopEnd;
8833 int maxLookaheadQueue = initialDelayNum + (gopSize - 1) + mulitcoreDelay;
8836 p_ctx->
max_frame_delay = ((maxDelayNum > maxLookaheadQueue) ? maxDelayNum : maxLookaheadQueue) + (mulitcoreDelay ? 4 : 0);
8859 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: firstGopEnd %d lookaheadGopEnd %d initialDelayNum %d maxDelayNum %d maxLookaheadQueue %d\n",
8860 __FUNCTION__, firstGopEnd, lookaheadGopEnd, initialDelayNum, maxDelayNum, maxLookaheadQueue);
8868 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: preset %d lookAheadDepth %d gopSize %d mulitcoreDelay %d "
8869 "last_gop_size %d linitial_frame_delay %d current_frame_delay %d max_frame_delay %d\n",
8886 if (p_enc->
qcomp != (
float)0.6)
8906 if (p_enc->
ipRatio != (
float)1.4)
8911 if (p_enc->
pbRatio != (
float)1.3)
8936 if (p_enc->
crfFloat != (
float)-1.0)
9068 for (i = 0; i < 8; i++)
9292 if( (!p_ctx) || (!p_config) )
9564 p_config->
i8crf = -1;
9622 p_config->
i8crfMax = (int8_t)(-1) + 1;
9623 p_config->
i32qcomp = (int32_t)(0.6 * 1000) + 1000;
9627 p_config->
i32ipRatio = (int32_t)(1.4 * 1000) + 1000;
9628 p_config->
i32pbRatio = (int32_t)(1.3 * 1000) + 1000;
9660 uint32_t max_err_len)
9666 char *p_param_warn = NULL;
9669 if (!p_ctx || !p_cfg || !p_param_err)
9687 memset(p_param_err, 0, max_err_len);
9688 memset(p_param_warn, 0, max_err_len);
9701 strncpy(p_param_err,
"Incompatible output format: hw frame must be used if out1 or out2 used", max_err_len);
9711 strncpy(p_param_err,
"ddr_priority_mode not supported on device with FW api version < 6.e",
9726 strncpy(p_param_err,
"Invalid crop offset: extends past 48x48 minimum window", max_err_len);
9733 strncpy(p_param_err,
"Invalid crop w or h: must be at least 48x48 minimum window", max_err_len);
9740 strncpy(p_param_err,
"Invalid crop w or h: must be smaller than input", max_err_len);
9747 strncpy(p_param_err,
"Invalid crop rect: must fit in input", max_err_len);
9756 strncpy(p_param_err,
"Invalid crop value: even values only", max_err_len);
9762 strncpy(p_param_warn,
"crop param used but output not enabled!", max_err_len);
9777 strncpy(p_param_err,
"Invalid scale dimensions: zero", max_err_len);
9785 strncpy(p_param_err,
"Invalid scale value: even values only", max_err_len);
9795 strncpy(p_param_err,
"Invalid scale dimensions: downscale only after cropping", max_err_len);
9802 strncpy(p_param_warn,
"scale param used but output not enabled!", max_err_len);
9810 strncpy(p_param_warn,
"force8bit or semiPlanar used but output not enabled!", max_err_len);
9824 strncpy(p_param_err,
9825 "Invalid pairing: out=HW must be set with tiled format",
9832 strncpy(p_param_err,
"Invalid pairing: VP9 not compatible with tiled format",
9843 strncpy(p_param_err,
9844 "Invalid scale height: mult of 4 only, >= 128",
9853 strncpy(p_param_err,
9854 "Invalid scale width: mult of 128 only, >= 144",
9865 strncpy(p_param_err,
9866 "Invalid crop height: mult of 4 only, >= 128",
9875 strncpy(p_param_err,
9876 "Invalid crop width: mult of 128 only, >= 144",
9884 strncpy(p_param_err,
"Force 8 bit: not supported with tiled format\n",
9895 strncpy(p_param_err, p_param_warn, max_err_len);
9905 static ni_retcode_t ni_check_level(
int level,
int codec_id)
9907 const int l_levels_264[] = {10, 11, 12, 13, 20, 21, 22, 30, 31, 32,
9908 40, 41, 42, 50, 51, 52, 60, 61, 62, 0};
9909 const int l_levels_265[] = {10, 20, 21, 30, 31, 40, 41,
9910 50, 51, 52, 60, 61, 62, 0};
9911 const int l_levels_av1[] = {20, 21, 30, 31, 40, 41, 50, 51, 0};
9912 const int *l_levels = l_levels_264;
9921 l_levels = l_levels_265;
9924 l_levels = l_levels_av1;
9927 while (*l_levels != 0)
9929 if (*l_levels == level)
9950 uint32_t max_err_len)
9958 if( (!p_ctx) || (!p_cfg) || (!p_src) || (!p_param_err) )
9968 memset(p_param_err, 0, max_err_len);
9969 memset(p_param_warn, 0, max_err_len);
9973 strncpy(p_param_err,
"Invalid frame_rate of 0 value", max_err_len);
9981 strncpy(p_param_err,
"Invalid i32frameRateInfo: too big", max_err_len);
9988 strncpy(p_param_err,
"Invalid i32bitRate: smaller than or equal to frame rate", max_err_len);
9995 strncpy(p_param_err,
"Invalid i32bitRate: too big", max_err_len);
10002 strncpy(p_param_err,
"Invalid i32bitRate: too low", max_err_len);
10009 strncpy(p_param_err,
"Invalid Picture Width: too small", max_err_len);
10016 strncpy(p_param_err,
"Invalid Picture Width: too big", max_err_len);
10023 strncpy(p_param_err,
"Invalid Picture Height: too small", max_err_len);
10030 strncpy(p_param_err,
"Invalid Picture Height: too big", max_err_len);
10040 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height (%u x %u): both need to be specified",
10048 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height (%u x %uu): must be even",
10056 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: less than %d",
10063 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: less than %d",
10070 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: exceeds %d",
10077 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: exceeds %d",
10084 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height: exceeds %d",
10094 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: exceeds %d",
10101 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: exceeds %d",
10108 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height: exceeds %d",
10117 strncpy(p_param_err,
"Invalid Crop Width: offset + crop width too big", max_err_len);
10123 strncpy(p_param_err,
"Invalid Crop Height: offset + crop height too big", max_err_len);
10134 snprintf(p_param_err, max_err_len,
"Invalid Picture Width: exceeds %d",
10141 snprintf(p_param_err, max_err_len,
"Invalid Picture Height: exceeds %d",
10148 snprintf(p_param_err, max_err_len,
"Invalid Picture Width x Height: exceeds %d",
10158 strncpy(p_param_err,
"Invalid input planar format: out of range", max_err_len);
10167 strncpy(p_param_err,
"Invalid input planar format for device with FW api version < 6.8",
10174 strncpy(p_param_err,
"Invalid Encoder Selected: Tiled format must be on same device",
10181 strncpy(p_param_err,
10182 "Invalid Picture Height: tiled format only supports "
10190 strncpy(p_param_err,
10191 "Invalid Picture Width: tiled format only supports "
10206 strncpy(p_param_err,
"zeroCopyMode must not be disabled for RGBA / BGRA / ABGR / ARGB pixel formats", max_err_len);
10216 strncpy(p_param_err,
"RGBA / BGRA pixel formats not supported on device with FW api version < 6.Y",
10229 strncpy(p_param_err,
"ddr_priority_mode not supported on device with FW api version < 6.e",
10239 strncpy(p_param_err,
"Invalid Encoder Level: out of range", max_err_len);
10249 strncpy(p_param_err,
"Invalid intra_mb_refresh_mode: out of range",
10261 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too small", max_err_len);
10268 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too big", max_err_len);
10280 strncpy(p_param_err,
10281 "Invalid custom GOP paramaters: custom gop size must > 0",
10292 strncpy(p_param_err,
10293 "Invalid custom GOP paramaters: selected gopPresetIdx is "
10294 "not compatible with custom gop",
10301 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too small", max_err_len);
10308 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too big", max_err_len);
10318 strncpy(p_param_err,
"Invalid custom gop parameters: poc_offset larger"
10319 " than GOP size", max_err_len);
10331 strncpy(p_param_warn,
"useLowDelayPocType is only supported for H.264. Change useLowDelayPocType to 0", max_err_len);
10339 strncpy(p_param_err,
10340 "entropyCodingMode is only supported for H.264.",
10350 strncpy(p_param_err,
10351 "av1ErrorResilientMode is only supported for AV1.",
10361 strncpy(p_param_err,
"qLevel is only supported for JPEG.",
10374 strncpy(p_param_warn,
"enableSSIM is not supported on device with FW api version < 6.2. Reported ssim will be 0.", max_err_len);
10383 strncpy(p_param_err,
"sliceMode/sliceArg is only supported for H.264 or H.265.",
10392 int max_num_ctu_mb_row = (p_src->
source_height + ctu_mb_size - 1) / ctu_mb_size;
10396 snprintf(p_param_err, max_err_len,
"Invalid number of rows per slice: should be between 1 and %d",
10407 strncpy(p_param_err,
"useLowDelayPocType is only supported for H.264.",
10425 strncpy(p_param_err,
10426 "this gopPreset is not supported for lookahead and/or CRF",
10434 bool bIsgopLowdelay =
true;
10442 bIsgopLowdelay =
false;
10448 bIsgopLowdelay =
false;
10452 if (bIsgopLowdelay)
10454 strncpy(p_param_err,
"B-frames low delay custom gop is not supported for "
10455 "lookahead and/or CRF", max_err_len);
10463 strncpy(p_param_err,
10464 "bitrateMode is invalid when lookahead is enabled (or in CRF mode)",
10486 strncpy(p_param_err,
10487 "gopPresetIdx 2 is obsolete, suggest to use gopPresetIdx 9 "
10510 strncpy(p_param_err,
10511 "gopPresetIdx 6 is obsolete, suggest to use gopPresetIdx 7 "
10549 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Force newRcEnable to 0 in 2-pass encode or in 1-pass average bitrate mode, with ipRatio, VbvMaxRate, or VbvMinRate\n");
10575 strncpy(p_param_err,
"Invalid profile: must be 5 (high10)",
10585 strncpy(p_param_err,
"Invalid profile: must be 1 (baseline), 2 (main),"
10586 " 3 (extended), 4 (high), or 5 (high10)", max_err_len);
10597 strncpy(p_param_err,
"Invalid gopPresetIdx for H.264 baseline profile:"
10598 " must be 1, 2, 6 or 0 (custom with no B frames)", max_err_len);
10610 strncpy(p_param_err,
"H.264 baseline profile: custom GOP can not "
10611 "have B frames", max_err_len);
10622 strncpy(p_param_err,
"Invalid profile: must be 1 (baseline), 2 (main),"
10623 " 4 (high), or 5 (high10)", max_err_len);
10629 strncpy(p_param_warn,
"AVC Baseline/Main/High Profile do not support 10-bit, auto convert to 8-bit", max_err_len);
10640 strncpy(p_param_err,
"H.264 baseline profile: custom GOP can not "
10641 "have B frames", max_err_len);
10655 strncpy(p_param_err,
10656 "Must use gopPresetIdx 1,9,10 (no "
10657 "B frames) for profile 1",
10667 strncpy(p_param_err,
"Tier is not supported for H.264", max_err_len);
10681 strncpy(p_param_err,
"Invalid profile: must be 2 (main10)",
10691 strncpy(p_param_err,
"Invalid profile: must be 1 (main) or 2 (main10)",
10702 strncpy(p_param_err,
"Invalid profile: must be 1 (main) or 2 (main10)",
10709 strncpy(p_param_warn,
"HEVC Main Profile does not support 10-bit, auto convert to 8-bit", max_err_len);
10717 strncpy(p_param_err,
"Invalid profile: must be 1 (main)",
10727 strncpy(p_param_warn,
10728 "AV1 level < 2.0 is not supported, change to level 2.0",
10734 strncpy(p_param_warn,
10735 "AV1 level > 5.1 is not supported, change to level 5.1",
10745 strncpy(p_param_warn,
"confWinTop is not supported in AV1",
10753 strncpy(p_param_warn,
"confWinBottom is not supported in AV1",
10761 strncpy(p_param_warn,
"confWinLeft is not supported in AV1",
10769 strncpy(p_param_warn,
"confWinRight is not supported in AV1",
10775 strncpy(p_param_err,
10776 "masterDisplay not supported for AV1",
10782 strncpy(p_param_err,
"hrdEnable is not supported on av1 encoder",
10789 strncpy(p_param_err,
"enableAUD is not supported on av1 encoder",
10796 strncpy(p_param_err,
"maxCLL is not supported on av1 encoder",
10803 strncpy(p_param_err,
"repeatHeaders is not supported on av1 encoder",
10809 strncpy(p_param_err,
"enableSSIM is not supported on av1 encoder",
10816 strncpy(p_param_err,
"EnableRdoQuant is not supported on av1 encoder",
10823 strncpy(p_param_err,
"fillerEnable is not supported on av1 encoder",
10830 strncpy(p_param_err,
"ppsInitQp is not supported for av1 encoder",
10839 strncpy(p_param_err,
10840 "masterDisplay not supported for jpeg",
10846 strncpy(p_param_err,
"confWinTop is not supported in jpeg",
10853 strncpy(p_param_err,
"confWinBottom is not supported in jpeg",
10860 strncpy(p_param_err,
"confWinLeft is not supported in jpeg",
10867 strncpy(p_param_err,
"confWinRight is not supported in jpeg",
10874 strncpy(p_param_err,
"hrdEnable is not supported on jpeg encoder",
10881 strncpy(p_param_err,
"enableAUD is not supported on jpeg encoder",
10888 strncpy(p_param_err,
"repeatHeaders is not supported on jpeg encoder",
10895 strncpy(p_param_err,
"prefTRC is not supported on jpeg encoder",
10902 strncpy(p_param_err,
"maxCLL is not supported on jpeg encoder",
10909 strncpy(p_param_err,
"colorPri is not supported on jpeg encoder",
10916 strncpy(p_param_err,
"colorTrc is not supported on jpeg encoder",
10923 strncpy(p_param_err,
"colorSpc is not supported on jpeg encoder",
10930 strncpy(p_param_err,
"sarNum is not supported on jpeg encoder",
10937 strncpy(p_param_err,
"sarDenom is not supported on jpeg encoder",
10944 strncpy(p_param_err,
10945 "videoFullRangeFlag is not supported on jpeg encoder",
10952 strncpy(p_param_err,
10953 "temporalLayersEnable is not supported on jpeg encoder",
10960 strncpy(p_param_err,
"LowDelay is not supported on jpeg encoder",
10967 strncpy(p_param_err,
"rdoLevel is not supported on jpeg encoder",
10974 strncpy(p_param_err,
"EnableRdoQuant is not supported on jpeg encoder",
10981 strncpy(p_param_err,
10982 "enable2PassGop is not supported on jpeg encoder",
10989 strncpy(p_param_err,
10990 "lookAheadDepth is not supported on jpeg encoder",
10997 strncpy(p_param_err,
10998 "gopPresetIdx is not supported on jpeg encoder",
11005 strncpy(p_param_err,
"roiEnable is not supported on jpeg encoder",
11012 strncpy(p_param_err,
11013 "RoiDemoMode is not supported on jpeg encoder",
11020 strncpy(p_param_err,
"cacheRoi is not supported on jpeg encoder",
11027 strncpy(p_param_err,
11028 "ReconfDemoMode is not supported on jpeg encoder",
11035 strncpy(p_param_err,
11036 "intraRefreshMode is not supported on jpeg encoder",
11043 strncpy(p_param_err,
11044 "intraRefreshArg is not supported on jpeg encoder",
11051 strncpy(p_param_err,
11052 "intraPeriod is not supported on jpeg encoder",
11061 "IntraRefreshResetOnForceIDR is not supported on jpeg encoder",
11068 strncpy(p_param_err,
11069 "longTermReferenceEnable is not supported on jpeg encoder",
11076 strncpy(p_param_err,
11077 "longTermReferenceInterval is not supported on jpeg encoder",
11084 strncpy(p_param_err,
11085 "longTermReferenceCount is not supported on jpeg encoder",
11092 strncpy(p_param_err,
11093 "multicoreJointMode is not supported on jpeg encoder",
11100 strncpy(p_param_err,
"enableSSIM is not supported on jpeg encoder",
11107 strncpy(p_param_err,
11108 "vbvBufferSize is not supported on jpeg encoder",
11115 strncpy(p_param_err,
11116 "fillerEnable is not supported on jpeg encoder",
11123 strncpy(p_param_err,
"picSkip is not supported on jpeg encoder",
11130 strncpy(p_param_err,
"maxFrameSize is not supported on jpeg encoder",
11137 strncpy(p_param_err,
11138 "cuLevelRCEnable is not supported on jpeg encoder",
11145 strncpy(p_param_err,
"hvsQPEnable is not supported on jpeg encoder",
11152 strncpy(p_param_err,
"profile is not supported on jpeg encoder",
11159 strncpy(p_param_err,
"intraRefreshMode or intraRefreshArg is not supported on jpeg encoder",
11164 if (p_cfg->
i8crf != -1)
11166 strncpy(p_param_err,
"crf is not supported on jpeg encoder",
11173 strncpy(p_param_err,
"tolCtbRcInter is not supported on jpeg encoder",
11180 strncpy(p_param_err,
"tolCtbRcIntra is not supported on jpeg encoder",
11187 strncpy(p_param_err,
11188 "rcQpDeltaRange is not supported on jpeg encoder",
11195 strncpy(p_param_err,
"bitrateWindow is not supported on jpeg encoder",
11202 strncpy(p_param_err,
"ctbRowQpStep is not supported on jpeg encoder",
11209 strncpy(p_param_err,
11210 "enableAIEnhance is not supported on jpeg encoder",
11217 strncpy(p_param_err,
"ppsInitQp is not supported for jpeg encoder",
11224 strncpy(p_param_err,
"pass1Qp is not supported for jpeg encoder",
11231 strncpy(p_param_err,
"bitrateMode is not supported for jpeg encoder",
11240 strncpy(p_param_err,
"Invalid forceFrameType: out of range",
11248 strncpy(p_param_err,
"Invalid forcedHeaderEnable: out of range",
11257 strncpy(p_param_err,
"Invalid decoding_refresh_type: out of range", max_err_len);
11267 strcpy(p_param_err,
"Invalid gop_preset_index: out of range");
11280 strcpy(p_param_err,
"GOP size must be 1 when lowDelay is enabled");
11289 strncpy(p_param_err,
"Invalid gopSize out of range", max_err_len);
11297 strncpy(p_param_err,
"GOP size must be <= 4 for low delay GOP", max_err_len);
11306 strncpy(p_param_err,
"Invalid LookAheadDepth: out of range. <[4-40]>", max_err_len);
11312 strncpy(p_param_err,
"2-pass encode does not support low delay GOP", max_err_len);
11318 strncpy(p_param_err,
"2-pass encode does not support tile4x4 format",
11335 strncpy(p_param_err,
"Custom GOP must not include backward prediction when lowDelay is enabled", max_err_len);
11337 strncpy(p_param_err,
"Custom GOP must not include backward prediction when picSkip is enabled", max_err_len);
11347 strncpy(p_param_err,
"Must use low delay GOP (gopPresetIdx 1,3,7,9,10) when lowDelay is enabled", max_err_len);
11349 strncpy(p_param_err,
"Must use low delay GOP (gopPresetIdx 1,3,7,9,10) when picSkip is enabled", max_err_len);
11355 strncpy(p_param_err,
"lookAheadDepth must be 0 when lowDelay is enabled", max_err_len);
11357 strncpy(p_param_err,
"lookAheadDepth must be 0 when picSkip is enabled", max_err_len);
11365 strncpy(p_param_err,
11366 "Cannot use multicoreJointMode when lowDelay is enabled",
11369 strncpy(p_param_err,
11370 "Cannot use multicoreJointMode when picSkip is enabled",
11379 strncpy(p_param_err,
11380 "Cannot enable minFramesDelay when lowDelay is enabled",
11383 strncpy(p_param_err,
11384 "Cannot enable minFramesDelay when picSkip is enabled",
11395 strncpy(p_param_err,
"Custom GOP size must be 1 when useLowDelayPocType is enabled", max_err_len);
11401 strncpy(p_param_err,
"Must use GOP with all frames as reference frames (gopPresetIdx 1,3,7,9) when useLowDelayPocType is enabled", max_err_len);
11424 "minimum frame size %d bytes in low delay mode\n", __func__,
11430 "mode. Set it to half of the maximum frame size %d bytes\n",
11437 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: maxFrameSize %u is too small. Changed to minimum value (bitrate/framerate in byte): %u\n",
11446 strncpy(p_param_err,
"maxFrameSize can only be used when lowDelay is enabled", max_err_len);
11463 strncpy(p_param_err,
"Custom GOP can not have B frames for intra refresh", max_err_len);
11473 strncpy(p_param_err,
11474 "Must use gopPresetIdx 9 (consecutive P frame) for intra refresh",
11479 strncpy(p_param_warn,
"GOP size forced to 1 and low delay GOP force disabled (no B frames) for intra refresh", max_err_len);
11486 strncpy(p_param_err,
11487 "intra refresh cycle (height / intraRefreshArg MB or CTU) must > 1",
11494 strncpy(p_param_err,
"lookaheadDepth must be 0 for intra refresh", max_err_len);
11503 strncpy(p_param_warn,
"intraPeriod forced to match intra refersh cycle (intraPeriod must >= intra refersh cycle)", max_err_len);
11511 strncpy(p_param_warn,
"intraPeriod forced to match intra refersh cycle (intraPeriod must >= intra refersh cycle)", max_err_len);
11537 snprintf(p_param_err, max_err_len,
"vbvMaxRate %u cannot be smaller than bitrate %d",
11549 snprintf(p_param_err, max_err_len,
"vbvMinRate %u cannot be larger than bitrate %d",
11564 snprintf(p_param_err, max_err_len,
"vbvBufferSize must be greater than the average frame size. Minimum is %u msec for framerate %d fps",
11576 snprintf(p_param_warn, max_err_len,
"vbvBufferSize cannot be smaller than one frame size based on vbvMaxRate, force vbvBufferSize to %u msec for bitrate %d vbvMaxRate %u and framerate %d fps",
11588 snprintf(p_param_warn, max_err_len,
"vbvBufferSize cannot be smaller than one frame size based on vbvMinRate, force vbvBufferSize to %u msec for bitrate %d vbvMinRate %u and framerate %d fps",
11600 snprintf(p_param_warn, max_err_len,
"vbvMaxRate %u vbvMinRate %u does not take effect when vbvBufferSize is 0, force vbvMaxRate vbvMinRate to 0",
11612 strncpy(p_param_err,
11613 "Can't enable ltrRefInterval and longTermReferenceEnable "
11624 strncpy(p_param_err,
"Custom GOP size can not be > 1 for long term reference", max_err_len);
11633 strncpy(p_param_err,
11634 "Must use low delay GOP (gopPresetIdx 1,3,7,9) for long term reference",
11639 strncpy(p_param_warn,
"GOP size forced to 1 for long term reference", max_err_len);
11646 strncpy(p_param_err,
"lookaheadDepth must be 0 for long term reference", max_err_len);
11656 "Must set longTermReferenceEnable for longTermReferenceInterval",
11666 strncpy(p_param_warn,
"AV1 err resilient mode forced to 0 when using other codecs", max_err_len);
11676 strncpy(p_param_err,
"Invalid cu_size_mode: out of range", max_err_len);
11686 strncpy(p_param_err,
"Invalid use_recommend_enc_params: out of range", max_err_len);
11704 strncpy(p_param_err,
"Invalid max_num_merge: out of range", max_err_len);
11718 strncpy(p_param_err,
"Invalid intra_qp: out of range", max_err_len);
11725 if (p_cfg->
i8crf >= 0 && p_cfg->
i8crf <= 51)
11732 strncpy(p_param_err,
"CRF requres LookAheadDepth <[4-40]>", max_err_len);
11740 strncpy(p_param_warn,
"enable lookahead of current frame", max_err_len);
11747 strncpy(p_param_err,
"CRF requires RcEnable 0", max_err_len);
11754 strncpy(p_param_warn,
"Lookahead with cuLevelRCEnable or hvsQPEnable may degrade quality", max_err_len);
11765 strncpy(p_param_err,
"tuneBframeVisual level 1 (medium) requires lookahead or crf encode", max_err_len);
11775 strncpy(p_param_err,
"Invalid enable_mb_level_rc: out of range", max_err_len);
11784 strncpy(p_param_err,
"Invalid min_qp: out of range", max_err_len);
11792 strncpy(p_param_err,
"Invalid max_qp: out of range", max_err_len);
11800 strncpy(p_param_err,
"Invalid enable_cu_level_rate_control: out of range", max_err_len);
11810 strncpy(p_param_err,
"Invalid enable_hvs_qp: out of range", max_err_len);
11820 strncpy(p_param_err,
"Invalid max_delta_qp: out of range", max_err_len);
11829 strncpy(p_param_err,
"Invalid i32vbvBufferSize: out of range", max_err_len);
11857 strncpy(p_param_err, p_param_warn, max_err_len);
11861 free(p_param_warn);
11867 char *p_param_err, uint32_t max_err_len)
11870 int32_t low_delay = 0;
11871 int32_t intra_period_gop_step_size;
11874 if (!p_param || !p_src || !p_param_err)
11883 memset(p_param_err, 0, max_err_len);
11917 intra_period_gop_step_size = 1;
11934 strncpy(p_param_err,
"Invalid intra_period and gop_preset_index: gop structure is larger than intra period", max_err_len);
11939 if (((!low_delay) && (p_param->
intra_period != 0) && ((p_param->
intra_period % intra_period_gop_step_size) != 0)) ||
11942 strncpy(p_param_err,
"Invalid intra_period and gop_preset_index: intra period is not a multiple of gop structure size", max_err_len);
11955 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id larger than 7", max_err_len);
11962 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id is zero or negative", max_err_len);
11967 if (min_poc > temp_poc[i])
11969 min_poc = temp_poc[i];
11977 if (temp_poc[j] == min_poc)
11986 strncpy(p_param_err,
"Invalid custom gop parameters: poc_offset is invalid", max_err_len);
12002 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id larger than 7", max_err_len);
12009 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id is negative", max_err_len);
12018 strncpy(p_param_err,
"Invalid custom gop parameters: ref pic delta cannot be 0", max_err_len);
12029 ni_log(
NI_LOG_ERROR,
"g%drefPic%d specified without g%drefPic%dUsed specified!\n", i, j, i, j);
12036 if (min_poc > temp_poc[i])
12038 min_poc = temp_poc[i];
12046 if (temp_poc[j] == min_poc)
12055 strncpy(p_param_err,
"Invalid custom gop parameters: poc_offset is invalid", max_err_len);
12073 if (((p_param->
cu_size_mode & 0x1) == 0) && ((align_8_width_flag != 0) || (align_8_height_flag != 0)))
12075 strncpy(p_param_err,
"Invalid use_recommend_enc_params and cu_size_mode: picture width and height must be aligned with 8 pixels when enable CU8x8 of cu_size_mode. Recommend to set cu_size_mode |= 0x1 (CU8x8)", max_err_len);
12079 else if (((p_param->
cu_size_mode & 0x1) == 0) && ((p_param->
cu_size_mode & 0x2) == 0) && ((align_16_width_flag != 0) || (align_16_height_flag != 0)))
12081 strncpy(p_param_err,
"Invalid use_recommend_enc_params and cu_size_mode: picture width and height must be aligned with 16 pixels when enable CU16x16 of cu_size_mode. Recommend to set cu_size_mode |= 0x2 (CU16x16)", max_err_len);
12085 else if (((p_param->
cu_size_mode & 0x1) == 0) && ((p_param->
cu_size_mode & 0x2) == 0) && ((p_param->
cu_size_mode & 0x4) == 0) && ((align_32_width_flag != 0) || (align_32_height_flag != 0)))
12087 strncpy(p_param_err,
"Invalid use_recommend_enc_params and cu_size_mode: picture width and height must be aligned with 32 pixels when enable CU32x32 of cu_size_mode. Recommend to set cu_size_mode |= 0x4 (CU32x32)", max_err_len);
12096 strncpy(p_param_err,
"Invalid conf_win_top: out of range", max_err_len);
12102 strncpy(p_param_err,
"Invalid conf_win_top: not multiple of 2", max_err_len);
12109 strncpy(p_param_err,
"Invalid conf_win_bottom: out of range", max_err_len);
12115 strncpy(p_param_err,
"Invalid conf_win_bottom: not multiple of 2", max_err_len);
12122 strncpy(p_param_err,
"Invalid conf_win_left: out of range", max_err_len);
12128 strncpy(p_param_err,
"Invalid conf_win_left: not multiple of 2", max_err_len);
12135 strncpy(p_param_err,
"Invalid conf_win_right: out of range", max_err_len);
12141 strncpy(p_param_err,
"Invalid conf_win_right: not multiple of 2", max_err_len);
12155 if( (!p_cfg) || (!p_param_err) )
12165 memset(p_param_err, 0, max_err_len);
12169 strncpy(p_param_err,
"Invalid roiEnable: out of range", max_err_len);
12176 strncpy(p_param_err,
"hvsQPEnable and roiEnable: not mutually exclusive", max_err_len);
12185 strncpy(p_param_err,
"Invalid min_qp(P/B) and max_qp(P/B): min_qp cannot be larger than max_qp", max_err_len);
12206 if (!p_encoder_params)
12335 ni_pthread_mutex_t *p_mutex;
12340 struct sched_param sched_param;
12346 sigfillset(&signal);
12357 if (((sched_param.sched_priority = sched_get_priority_max(SCHED_RR)) ==
12359 sched_setscheduler(syscall(SYS_gettid), SCHED_RR, &sched_param) < 0)
12363 if (setpriority(PRIO_PROCESS, 0, -20) != 0)
12370 #elif defined(_WIN32)
12375 if (SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL) ==
12386 char name[16] = {0};
12387 snprintf(name,
sizeof(name),
"%s%.2x%.4x",
"KAT", args->
hw_id, args->
session_id);
12389 prctl(PR_SET_NAME, name);
12391 pthread_setname_np(name);
12410 "%s creation timeout. session_id=0x%X requested timeout: %" PRIu64
12411 "ns, ping time delta: %" PRIu64
"ns\n ",
12463 "Persistent failures detected, %s() line-%d: session_no 0x%x sess_err_no %u "
12464 "inst_err_no %u\n",
12477 "%s was possibly blocked. session_id=0x%X requested timeout: %" PRIu64
12478 "ns, ping time delta: %" PRIu64
"ns\n ",
12499 endtime += interval;
12544 void * p_buffer = NULL;
12545 uint32_t ui32LBA = 0;
12546 uint32_t modelled_load;
12620 "ERROR %s(): p_ctx->device_handle=%" PRIx64
12621 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
12629 "Uploader open session ID:0x%x,timestamp:%" PRIu64
"\n",
12633 uint64_t keep_alive_timeout =
12636 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
12638 keep_alive_timeout);
12649 "ERROR %s(): nvme write keep_alive_timeout command "
12650 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
12674 modelled_load >>= 10;
12679 memcpy(p_buffer, &modelled_load, 4);
12710 "%s(): p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, "
12711 "p_ctx->session_id=%d\n",
12720 retval = p2p_fill_pcie_address(p_ctx);
12744 if (!src_p_ctx || !dst_p_ctx)
12746 ni_log(
NI_LOG_ERROR,
"ERROR %s(): passed parameters are null!, return\n", __func__);
12757 if (src_p_ctx->
isP2P)
12762 dst_p_ctx->
bus = src_p_ctx->
bus;
12763 dst_p_ctx->
dev = src_p_ctx->
dev;
12764 dst_p_ctx->
fn = src_p_ctx->
fn;
12785 uint32_t sent_size = 0;
12786 uint32_t frame_size_bytes = 0;
12787 uint32_t retry_count = 0;
12796 if (!p_ctx || !p_frame)
12815 #ifdef MEASURE_LATENCY
12820 abs_time_ns, p_frame->
pts);
12837 query_sleep(p_ctx);
12846 if (retry_count >= 500)
12849 "hwupload write exceeded max query retries. rc=%d try=%d"
12851 retval, retry_count);
12872 "size %u >= frame size %u , retry %u\n",
12876 #ifdef XCODER_TIMESTAMP_DTS_ENABLED
12882 "ERROR %s(): ni_timestamp_register() for dts "
12895 if (separate_metadata)
12900 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR %s(): uploader separated metadata not supported on device with FW api version < 6.S\n",
12908 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR %s(): p_metadata_buffer is NULL, allocation failed?\n",
12918 if (separate_start)
12931 "%s(): %d.%u p_ctx->frame_num=%" PRIu64
", "
12932 "p_frame->video_width=%u, p_frame->video_height=%u, "
12933 "start_len [%u,%u,%u] inconsecutive_transfer %u\n",
12939 uint32_t ui32LBA_metadata =
12942 "%s: p_metadata_buffer = %p, metadata_buffer_size "
12943 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
12967 if (separate_start)
12980 "%s: p_start_buffer = %p, p_frame->start_buffer_size "
12981 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
13009 "%s: p_data = %p, p_frame->buffer_size "
13010 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
13017 if (separate_start)
13042 "%s: p_data = %p, p_frame->buffer_size = %u, "
13043 "p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
13047 sent_size = frame_size_bytes;
13048 if (separate_start)
13076 size = frame_size_bytes;
13078 #ifdef XCODER_DUMP_DATA
13079 char dump_file[256];
13080 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-hwup-fme/fme-%04ld.yuv",
13083 FILE *f = fopen(dump_file,
"wb");
13092 #ifdef MEASURE_LATENCY
13131 int query_retry = 0;
13135 if (!p_ctx || !hwdesc)
13153 query_sleep(p_ctx);
13172 if (query_retry >= 1000)
13214 void* p_buffer = NULL;
13216 uint32_t ui32LBA = 0;
13241 NI_INVALID_DEVICE_HANDLE, p_buffer,
13270 uint64_t frame_offset = 0;
13271 uint8_t *p_data_buffer = NULL;
13277 uint32_t total_bytes_to_read = 0;
13278 uint32_t total_yuv_met_size = 0;
13279 uint32_t read_size_bytes = 0;
13281 int query_retry = 0;
13282 uint32_t ui32LBA = 0;
13283 unsigned int bytes_read_so_far = 0;
13285 int low_delay_notify = 0;
13287 uint32_t frames_dropped = 0;
13289 uint8_t get_first_metadata = 0;
13290 uint8_t sequence_change = 0;
13294 if (!p_ctx || !p_frame)
13313 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
13318 total_bytes_to_read = p_frame->
data_len[3] + metadata_hdr_size;
13321 "Total bytes to read %u total_yuv_met_size %u, low_delay %u\n",
13342 query_sleep(p_ctx);
13351 &sessionStatistic);
13375 if (query_retry >= 1000)
13378 "\n", query_retry, retval);
13380 low_delay_notify = 1;
13395 "Dec read desc only hdr metadata is available. Seq change may "
13396 "have occured.\n");
13397 total_bytes_to_read = metadata_hdr_size;
13398 sequence_change = 1;
13402 ni_log2(p_ctx,
NI_LOG_TRACE,
"Dec read desc buf_size < frame_size. Retry %d\n", query_retry);
13408 "Dec read desc query, ready_to_close %u, query eos\n",
13423 "WARNING: Dec read desc query eos reached but exceeded max "
13424 "retries. is_flushed=%u try=%d.\n",
13429 "Dec read desc query eos reached. is_flushed=%u try=%d"
13434 low_delay_notify = 1;
13441 "Dec read desc available buf size == %d, query try %d, "
13455 query_retry < 1000 / 2)
13462 low_delay_signal(p_ctx);
13478 low_delay_signal(p_ctx);
13481 "input (B frames)? Just cancel the low delay mode then\n");
13484 low_delay_signal(p_ctx);
13494 if(query_retry <= 2000)
13503 "Warning: decoder pkt_num %u frame_num %u "
13504 "timeout, increaing pkt_delay_cnt to %u\n",
13511 "\n", query_retry, retval);
13527 "At least %d packets should be sent before reading the "
13544 "%ux%u frame-rate %u is_flushed %u\n",
13572 total_bytes_to_read = p_frame->
data_len[3] + metadata_hdr_size;
13573 p_data_buffer = (uint8_t*)p_frame->
p_buffer;
13583 ni_log2(p_ctx,
NI_LOG_DEBUG,
"total_bytes_to_read %u max_nvme_io_size %u ylen %u cr len "
13584 "%u cb len %u hdr %d\n",
13587 p_frame->
data_len[2], metadata_hdr_size);
13595 "ERROR %s() avaliable size(%u) less than "
13599 }
else if (total_bytes_to_read == metadata_hdr_size && !p_ctx->
frame_num)
13606 void *p_metadata_buffer = NULL;
13616 p_data_buffer = (uint8_t *)p_metadata_buffer;
13617 get_first_metadata = 1;
13618 sequence_change = 0;
13629 read_size_bytes = total_bytes_to_read;
13637 p_data_buffer, read_size_bytes, ui32LBA);
13646 }
else if (get_first_metadata) {
13654 get_first_metadata = 0;
13670 low_delay_notify = 1;
13673 p_data_buffer = (uint8_t *)p_frame->
p_buffer +
13675 memcpy(p_meta, p_data_buffer, metadata_hdr_size);
13680 metadata_hdr_size);
13712 "p_data3_1:sei_size=%d device_handle=%d == hw_id=%d ses_id=%d\n",
13716 "p_data3_1: ui16FrameIdx=%d NodeAddre=0x%x planar=%d bd=%d\n",
13721 "p_data3_2:sei_size=%d device_handle=%d == hw_id=%d ses_id=%d\n",
13725 "p_data3_2: ui16FrameIdx=%d NodeAddre=0x%x planar=%d bd=%d\n",
13730 "%s:sei_size=%d device_handle=%d == hw_id=%d "
13735 "%s: session=0x%x ui16FrameIdx=%u NodeAddress=0x%x, "
13736 "planar=%d bd=%d\n",
13751 total_bytes_to_read = total_bytes_to_read + sei_size;
13753 "%s decoder read desc success, retval %d "
13754 "total_bytes_to_read include sei %u sei_size %d\n",
13755 __func__, retval, total_bytes_to_read, sei_size);
13769 bytes_read_so_far = total_bytes_to_read;
13771 rx_size =
ni_create_frame(p_frame, bytes_read_so_far, &frame_offset,
true);
13786 "is cancelled due to has_b_frames, frame_num %u\n",
13821 if (p_frame->
pts >= p_frame->
dts &&
13822 p_frame->
pts - p_frame->
dts < 1000)
13873 __func__, num_fw_pkts,
13877 bool bFound = (num_fw_pkts >= cumul);
13878 while (cumul < num_fw_pkts)
13884 "Invalid index computation > "
13885 "NI_MAX_DEC_REJECT!\n");
13892 "%s: idx %d pkt_offsets_index[idx] %" PRIu64
"\n",
13902 "%s: (first frame) idx %d last_dts %" PRId64
""
13903 " dts %" PRId64
" last_pts %" PRId64
" pts %" PRId64
"\n",
13910 "%s(): session %u recovering and "
13921 "%s: (zero default) dts %" PRId64
" pts "
13923 __func__, p_frame->
dts, p_frame->
pts);
13930 "%s: (not bitstream) dts %" PRId64
" pts "
13932 __func__, p_frame->
dts, p_frame->
pts);
13937 int64_t pts_delta = p_frame->
dts - p_ctx->
last_dts;
13942 "%s: (!is_first_frame idx) last_dts %" PRId64
""
13943 " dts %" PRId64
" pts_delta %" PRId64
" last_pts "
13944 "%" PRId64
" pts %" PRId64
"\n",
13945 __func__, p_ctx->
last_dts, p_frame->
dts, pts_delta,
13969 "%s: (found pts) dts %" PRId64
" pts "
13970 "%" PRId64
" frame_offset %" PRIu64
" i %d "
13971 "pkt_offsets_index_min %" PRIu64
" "
13972 "pkt_offsets_index %" PRIu64
" pkt_pos %" PRIu64
"\n",
13973 __func__, p_frame->
dts, p_frame->
pts, frame_offset, i,
13994 "ERROR: Frame pts %" PRId64
" not found for offset "
13995 "%" PRIu64
"\n", p_frame->
pts, frame_offset);
13997 "%s: (not found use default) dts %" PRId64
" pts %" PRId64
13999 __func__, p_frame->
dts, p_frame->
pts);
14007 p_frame->
pts = guess_correct_pts(p_ctx, p_frame->
pts, p_frame->
dts);
14015 __func__, p_frame->
pts);
14018 #ifdef MEASURE_LATENCY
14029 "%s(): p_frame->start_of_stream=%u, "
14030 "p_frame->end_of_stream=%u, p_frame->video_width=%u, "
14031 "p_frame->video_height=%u\n",
14040 "Decoder pts queue size = %d dts queue size = %d\n\n",
14047 #ifdef MEASURE_LATENCY
14052 ni_log2(p_ctx,
NI_LOG_INFO,
"DTS:%" PRId64
",DELTA:%" PRId64
",dLAT:%" PRIu64
";\n",
14063 if (get_first_metadata && p_data_buffer)
14065 if (sequence_change && p_ctx->
frame_num)
14079 low_delay_signal(p_ctx);
14086 if (low_delay_notify)
14088 low_delay_signal(p_ctx);
14106 uint64_t frame_offset = 0;
14107 uint8_t *p_data_buffer;
14110 uint32_t total_bytes_to_read = 0;
14111 uint32_t read_size_bytes = 0;
14112 uint32_t ui32LBA = 0;
14121 if ((!p_ctx) || (!p_frame))
14136 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
14138 if (!p_frame->
p_data[0] || !p_data_buffer)
14160 "ERROR %s(): NI_PIXEL_PLANAR_FORMAT_TILED4X4 not supported in download.\n",
14167 unsigned int bytes_read_so_far = 0;
14170 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Total bytes to download %u, start offset = %u, chunkOffset "
14171 "%u, minorOffset %u\n",
14173 output_chunk_offset, output_minor_offset);
14175 ni_log2(p_ctx,
NI_LOG_DEBUG,
"total_bytes_to_read %u max_nvme_io_size %u ylen %u cr len "
14176 "%u cb len %u hdr %d\n",
14179 p_frame->
data_len[2], metadata_hdr_size);
14198 "Config HW download read desc success, retval %d total_bytes_to_read %u\n",
14199 retval, total_bytes_to_read);
14202 read_size_bytes = total_bytes_to_read;
14204 ui32LBA += output_chunk_offset;
14212 NI_INVALID_DEVICE_HANDLE, p_data_buffer, read_size_bytes, ui32LBA);
14224 "HW download read desc success, retval %d total_bytes_to_read %u\n",
14225 retval, total_bytes_to_read);
14242 "Unconfig HW download read desc success, retval %d total_bytes_to_read %u\n",
14243 retval, total_bytes_to_read);
14246 bytes_read_so_far = total_bytes_to_read;
14251 rx_size = (int)bytes_read_so_far;
14260 __func__, rx_size);
14262 "%s(): p_frame->start_of_stream=%u, "
14263 "p_frame->end_of_stream=%u, p_frame->video_width=%u, "
14264 "p_frame->video_height=%u\n",
14268 "%s(): p_ctx->frame_num %" PRIu64
", "
14269 "p_frame->data_len[0/1/2]=%u/%u/%u\n",
14298 uint64_t frame_offset = 0;
14299 uint8_t *p_data_buffer;
14302 uint32_t total_bytes_to_read = 0;
14303 uint32_t read_size_bytes = 0;
14304 uint32_t ui32LBA = 0;
14306 const char *error_flag =
"NetintQuadraErr";
14310 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
14312 if (!p_frame->
p_data[0] || !p_data_buffer || 0 == p_frame->
data_len[0])
14314 ni_log(
NI_LOG_ERROR,
"ERROR %s(): passed parameters are null or p_frame->data_len is 0.\n",
14326 "ERROR %s(): Unsupported format %d for hw download.\n",
14333 unsigned int bytes_read_so_far = 0;
14338 "%u cb len %u hdr %d\n",
14339 total_bytes_to_read,
14341 p_frame->
data_len[2], metadata_hdr_size);
14346 memcpy(global_state->
error_flag, error_flag, strlen(error_flag)+1);
14350 read_size_bytes = total_bytes_to_read;
14352 ui32LBA += output_chunk_offset;
14358 "%u, minorOffset %u hwdesc->ui16FrameIdx %d ui32LBA 0x%x\n",
14360 output_chunk_offset, output_minor_offset, hwdesc->
ui16FrameIdx, ui32LBA);
14364 NI_INVALID_DEVICE_HANDLE, p_data_buffer, read_size_bytes, ui32LBA);
14373 if (!strcmp(global_state->
error_flag, error_flag) &&
14377 "size %u + offset %u out of range\n",
14378 __func__, hwdesc->
ui16FrameIdx, read_size_bytes, output_chunk_offset);
14383 bytes_read_so_far = total_bytes_to_read;
14388 rx_size = (int)bytes_read_so_far;
14396 "HW download read desc success, retval %d total_bytes_to_read %u\n",
14397 retval, total_bytes_to_read);
14416 uint8_t *p_data = NULL;
14418 uint32_t ui32LBA = 0;
14439 memset(p_data, 0, dataLen);
14441 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s(): ui16DstIdx %u, ui16SrcIdx %u, size %u, offset %u\n", __func__,
14447 p_data, dataLen, ui32LBA);
14504 uint32_t pool_size,
14507 void* p_uploader_config = NULL;
14511 uint32_t ui32LBA = 0;
14539 memset(p_uploader_config, 0, buffer_size);
14561 ni_log2(p_ctx,
NI_LOG_DEBUG,
"ni_config_instance_set_uploader_params():%d x %d x Format %d with %d framepool\n",
14569 p_uploader_config, buffer_size, ui32LBA);
14608 void* p_decoder_config = NULL;
14611 uint32_t ui32LBA = 0;
14632 ni_log2(p_ctx,
NI_LOG_INFO,
"%s() FW rev %s < 6rT-- load balancing might be affected\n", __func__,
14644 memset(p_decoder_config, 0, buffer_size);
14697 p_decoder_config, buffer_size, ui32LBA);
14740 int query_retry = 0;
14771 if (query_retry >= 1000)
14794 if (query_retry >= 1000)
14805 "Session=0x%x: %s got FrameIndex=%u\n",
14821 "%s Warning scalar read hwdesc fail rc %d or ind !\n",
14903 uint32_t *p_offset)
14915 "FrameIdx %d OOR (%d,%d]. DDR config %d \n", __func__, hwdesc->
ui16FrameIdx,
14930 void *nb_data, uint32_t nb_size)
14932 void *p_ai_config = NULL;
14933 void *p_nb_data = NULL;
14934 uint32_t buffer_size;
14938 uint32_t ui32LBA = 0;
14939 uint32_t config_size;
14940 void *p_buffer = NULL;
14943 int retry_count = 0;
14974 ((
ni_ai_config_t *)p_ai_config)->ui32NetworkBinarySize = nb_size;
14987 memcpy(p_nb_data, nb_data, nb_size);
14995 p_ai_config, config_size, ui32LBA);
15001 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
15002 ", hw_id, %u, xcoder_inst_id: %d\n",
15009 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
15010 ", hw_id, %u, xcoder_inst_id: %d\n",
15031 memset(p_buffer, 0, dataLen);
15044 p_buffer, dataLen, ui32LBA);
15076 "AI write query failed or buf_size %u < "
15082 "Info ai write query success, available buf "
15083 "size %u >= frame size %u !\n",
15107 p_nb_data, buffer_size, ui32LBA);
15114 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
15115 ", hw_id, %u, xcoder_inst_id: %d\n",
15122 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
15123 ", hw_id, %u, xcoder_inst_id: %d\n",
15135 for (transferred = 0; transferred < buffer_size; transferred += this_size)
15139 (buffer_size - transferred);
15141 if (this_size & (4096 - 1))
15143 this_size = (this_size + (4096 - 1)) & ~(4096 - 1);
15147 (transferred >> 12);
15149 "%s(): write nb LBA 0x%x, this_size %u, page_offset %u\n",
15150 __func__, ui32LBA, this_size, (transferred >> 12));
15151 p_data = (uint8_t *)p_nb_data + transferred;
15154 (uint8_t *)p_nb_data + transferred, this_size, ui32LBA);
15162 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
15163 ", hw_id, %u, xcoder_inst_id: %d\n",
15171 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
15172 ", hw_id, %u, xcoder_inst_id: %d\n",
15199 void *p_buffer = NULL;
15200 uint32_t ui32LBA = 0;
15201 int retry_count = 0;
15212 memset(p_buffer, 0, dataLen);
15217 p_buffer, dataLen, ui32LBA);
15255 uint32_t ui32LBA = 0;
15257 uint32_t frame_size_bytes;
15258 uint32_t sent_size = 0;
15259 int32_t query_retry = 0;
15263 if (!p_ctx || !p_frame)
15290 frame_size_bytes = p_frame->
data_len[0];
15301 "Info ai write query success, available buf "
15302 "size %u >= frame size %u !\n",
15329 "AI write query failed or buf_size < frame_size. Retry %d\n",
15335 "AI write query exceeded max retries: %d\n",
15349 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Ai session write: p_data = %p, p_frame->buffer_size = %u, "
15350 "p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
15354 sent_size = frame_size_bytes;
15362 p_frame->
p_buffer, sent_size, ui32LBA);
15391 retval = frame_size_bytes;
15405 uint32_t actual_read_size = 0;
15407 uint32_t ui32LBA = 0;
15412 if (!p_ctx || !p_packet || !p_packet->
p_data)
15437 "Info ai read query success, available buf "
15438 "size %u >= frame size %u !\n",
15461 "Info ai read query rc %d, available buf size %u, "
15462 "frame_num=%" PRIu64
", pkt_num=%" PRIu64
"\n",
15483 actual_read_size = p_packet->
data_len;
15491 p_packet->
p_data, actual_read_size, ui32LBA);
15541 void *p_buffer = NULL;
15542 void *p_info = NULL;
15544 uint32_t ui32LBA = 0;
15546 int32_t query_retry = 0;
15549 uint32_t buffer_size;
15550 uint32_t this_size;
15552 uint32_t total_io_num;
15556 if (!p_ctx || !p_network)
15568 "ERROR: %s(): network parameters data is already initialized\n",
15594 memset(p_buffer, 0, dataLen);
15610 p_buffer, dataLen, ui32LBA);
15626 if (query_retry > 50000)
15629 __func__, query_retry - 1);
15674 if (!network_data->
inset)
15697 memset(p_info, 0, dataLen);
15701 p_info, dataLen, ui32LBA);
15702 if ((int32_t)retval < 0)
15724 memset(p_info, 0, dataLen);
15728 p_info, dataLen, ui32LBA);
15729 if ((int32_t)retval < 0)
15739 for (l = 0, network_data->
input_num = 0; l < 4; l++)
15749 for (l = 0, network_data->
output_num = 0; l < 4; l++)
15760 for (l = 0, buffer_size = 0; l < network_data->
input_num; l++)
15767 buffer_size += this_size;
15771 "%s(): network input layer %d: dims %u, %u/%u/%u/%u, f %d, q %d\n",
15777 for (l = 0, buffer_size = 0; l < network_data->
output_num; l++)
15784 buffer_size += this_size;
15788 "%s(): network output layer %d: dims %u, %u/%u/%u/%u, f %d, q %d\n",
15803 ni_unreference_network_data(network_data);
15814 void *p_buffer = NULL;
15815 uint32_t ui32LBA = 0;
15895 "ERROR %s(): p_ctx->device_handle=%" PRIx64
15896 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
15913 "%s(): p_ctx->device_handle=%" PRIx64
15914 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
15919 uint64_t keep_alive_timeout =
15922 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
15924 keep_alive_timeout);
15936 "ERROR %s(): nvme write keep_alive_timeout command "
15937 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
15948 "ERROR %s(): Unable to allocate network_data memory\n");
15972 void *p_buffer = NULL;
15973 uint32_t ui32LBA = 0;
16009 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
16010 "p_ctx->session_id=%d, close_mode=1\n",
16081 void *p_read_data = NULL;
16083 uint32_t ui32LBA = 0;
16100 int32_t query_retry = 0;
16108 "Info ai write query success, available buf "
16125 "AI write query failed or buf_size < frame_size. Retry %d\n",
16131 "AI write query exceeded max retries: %d\n",
16154 memset(p_data, 0x00, dataLen);
16160 for(
int i = 0; i < numInCfgs; i++){
16172 p_data, dataLen, ui32LBA);
16180 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
16181 ", hw_id, %u, xcoder_inst_id: %d\n",
16192 if (p_read_data != NULL)
16204 void *p_read_data = NULL;
16206 uint32_t ui32LBA = 0;
16227 "Error: %s function not supported on device with FW API version < 6rL\n",
16234 int query_retry = 0;
16245 memset(p_read_data, 0, dataLen);
16253 p_read_data, dataLen, ui32LBA);
16277 if (query_retry > 2000)
16280 __func__, query_retry - 1);
16298 if (p_read_data != NULL)
16306 int height,
int options,
int pool_size,
16311 void *p_read_data = NULL;
16313 uint32_t ui32LBA = 0;
16333 int query_retry = 0;
16344 memset(p_read_data, 0, dataLen);
16352 p_read_data, dataLen, ui32LBA);
16369 if (query_retry > 2000)
16372 __func__, query_retry - 1);
16390 int32_t query_retry = 0;
16398 "Info ai write query success, available buf "
16415 "AI write query failed or buf_size < frame_size. Retry %d\n",
16421 "AI write query exceeded max retries: %d\n",
16444 memset(p_data, 0x00, dataLen);
16459 p_data, dataLen, ui32LBA);
16467 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
16468 ", hw_id, %u, xcoder_inst_id: %d\n",
16480 if (p_read_data != NULL)
16503 int retry_count = 0;
16530 if (retry_count >= 500)
16556 if (retry_count >= 500)
16593 void *p_buffer = NULL;
16596 ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
16602 if (NI_INVALID_DEVICE_HANDLE == device_handle)
16677 uint8_t ddr_priority_mode)
16679 void *p_buffer = NULL;
16688 ddr_priority_mode);
16690 if (NI_INVALID_DEVICE_HANDLE == device_handle)
16709 p_cfg->
ddr_mode = ddr_priority_mode;
16714 ddr_priority_mode);
16742 void *metadata_buffer = NULL;
16745 if ((!p_frame) || (extra_len <= 0))
16748 "ERROR: %s passed parameters are null or not supported, "
16749 "p_frame %p, extra_len %d",
16750 __func__, p_frame, extra_len);
16754 int buffer_size = extra_len;
16766 "%s: free current p_frame metadata buffer, "
16767 "p_frame->buffer_size=%u\n",
16780 "ERROR %d: %s() Cannot allocate metadata buffer.\n",
16787 memset(metadata_buffer, 0, buffer_size);
16798 "%s: success: p_frame->p_metadata_buffer %p "
16799 "p_frame->metadata_buffer_size=%u\n",
16828 void *start_buffer = NULL;
16834 "ERROR: %s passed parameters are null or not supported, "
16836 __func__, p_frame);
16847 "ERROR %d: %s() Cannot allocate start buffer.\n",
16865 "%s: success: p_frame->p_start_buffer %p "
16866 "p_frame->start_buffer_size=%u\n",
16883 void *p_buffer = NULL;
16885 uint32_t ui32LBA = 0;
16888 if (!p_ctx || !p_metrics)
16891 "ERROR: %s() passed parameters are null!, return\n", __func__);
16915 p_buffer, dataLen, ui32LBA);
16958 buf[0] = (uint8_t)key;
16959 buf[1] = (uint8_t)value;
16972 CoreName = (
char *)
"all";
16975 CoreName = (
char *)
"np";
16978 CoreName = (
char *)
"ep";
16981 CoreName = (
char *)
"dp";
16984 CoreName = (
char *)
"tp";
16987 CoreName = (
char *)
"fp";
16990 CoreName = (
char *)
"Not Found";
17030 char *core_name = NULL;
17031 FILE *p_file = NULL;
17034 if (!p_ctx || !p_data)
17037 __func__, __LINE__, p_ctx, p_data);
17042 *(uint8_t *)p_data = 0x55;
17048 __func__, __LINE__, core_id);
17059 __func__, __LINE__, rc, core_name);
17061 else if (gen_log_file)
17064 char filename[32] =
"raw_";
17065 strcat(filename, core_name);
17066 strcat(filename,
"_slot_");
17068 bool pcie_id_name =
false;
17069 char devFilePath[1024] = {0};
17070 char devFDPath[1024] = {0};
17071 char pcie[64] = {0};
17072 char domain[5] = {0}, slot[3] = {0}, dev[3] = {0}, func[2] = {0};
17074 snprintf(devFDPath,
sizeof(devFDPath),
"/proc/self/fd/%d", p_ctx->
blk_io_handle);
17075 ssize_t len = readlink(devFDPath, devFilePath,
sizeof(devFilePath)-1);
17077 devFilePath[len] =
'\0';
17079 if (strstr(devFilePath,
"/dev/nvme") != NULL)
17082 if (strlen(pcie) > 0 && strlen(slot) > 0 && strlen(domain) > 0)
17084 strcat(filename, slot);
17085 strcat(filename,
"_");
17086 strcat(filename, domain);
17087 pcie_id_name =
true;
17092 ni_log2(p_ctx,
NI_LOG_INFO,
"%s:():%d: For dev %d can't look up PCI domain and slot info. Defaulting to slot=hw_id and domain=0000\n",
17095 snprintf(num, 4,
"%d", p_ctx->
hw_id);
17096 strcat(filename, num);
17097 strcat(filename,
"_0000");
17099 strcat(filename,
".bin");
17104 snprintf(num, 4,
"%02x", p_ctx->
hw_id);
17105 strcat(filename, num);
17106 strcat(filename,
"_0000");
17107 strcat(filename,
".bin");
17111 p_file = fopen(filename,
"wb");
17115 if (fwrite((uint8_t *)p_data ,
17116 data_len, 1, p_file) != 1)
17119 __func__, __LINE__, data_len);
17123 if (fflush(p_file))
17134 __func__, __LINE__, filename);
17146 if (!p_ctx || !p_data)
17149 __func__, __LINE__, p_ctx, p_data);
17164 uint64_t ui64DestAddr,
17165 uint32_t ui32FrameSize)
17167 void *p_buffer = NULL;
17183 p_data = (uint8_t *) p_buffer;
17186 memcpy(p_data, &ui64DestAddr,
sizeof(uint64_t));
17187 memcpy(p_data + 8, &ui32FrameSize,
sizeof(uint32_t));
17188 memcpy(p_data + 12, &source->
ui16FrameIdx,
sizeof(uint16_t));
17190 memcpy(p_data + 18, &ui16Direction,
sizeof(uint16_t));
17195 NI_INVALID_DEVICE_HANDLE, p_buffer,
17207 if (p_buffer != NULL)
17217 void *p_buffer = NULL;
17219 uint32_t ui32LBA = 0;
17223 uint32_t ui32Dummy = 0;
17245 p_data = (uint8_t *) p_buffer;
17249 memcpy(p_data + 8, &ui32Dummy, 4);
17252 memcpy(p_data + 18, &ui16Direction, 2);
17257 memcpy(&p_data[24] + (i*8), &dmaAddrs->
ui64DMAAddr[i], 8);
17279 if (p_buffer != NULL)